-1

I have a script that generates seo-friendly URLs like:

mydomain.com/song_here-is-the-song-title_3bhbex.html 
or 
mydomain.com/song_this-is-one-more-song_4mb6mb.html

So it is generate like this scheme: song_TITLE-OF-SONG_RANDOMID.html

How can I get this random-ID to foward it via htaccess? Right now I have

RewriteRule ^song_([0-9]+)\.html$ /song-text.php?id=$1 [L]

I need to change this rule, cause now I also have the songtitle as a slug and the ID is now also letters (not only digits).

How do I have to change my htaccess?

Thank you!

Tirenty2
  • 59
  • 7
  • 1
    Possible duplicate of [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Adam Nov 15 '17 at 15:29
  • Ok, so that's the your rule you have (made?). But what were your attempts to change it? Did none of the thousands of similar previous questions provide any help? Why and how did you try? – mario Nov 15 '17 at 15:36
  • RewriteRule ^song_([a-zA-Z0-9]+).html$ /song-text.php?id=$1 – eMRe Nov 15 '17 at 15:40
  • @emre: but the song-title can change. I need just the id (last six letters/digits before the .thml) – Tirenty2 Nov 15 '17 at 16:55
  • ^song_([a-zA-Z0-9]+)_([a-zA-Z0-9]+).html$ /song-text.php?title=$1&id=$2 – eMRe Nov 15 '17 at 18:45
  • It means you need to pass two variables. Title and id – eMRe Nov 15 '17 at 18:55
  • Try this: RewriteRule ^song_([a-zA-Z0-9_]+).html$ /song-text.php?id=$1 – eMRe Nov 15 '17 at 22:49

1 Answers1

1

This will work.

RewriteRule ^song_([a-zA-Z0-9_]+).html$ /song-text.php?id=$1

eMRe
  • 2,523
  • 5
  • 30
  • 44
  • Code-only answers are low value on StackOverflow. Every time you post an answer, endeavor to educate the OP and thousands of future researchers with your post. Please improve this answer. – mickmackusa Mar 12 '18 at 04:14