Search code examples
php.htaccessslug

Redirect seo-friendly URLs (htaccess)


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!


Solution

  • This will work.

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