Busker McGreen Brian Busker McGreen Brian - 7 months ago 12
PHP Question

htaccess: RewriteRule for URL rewriting

I have a link that looks like this

http://www.example.com/artistmusic?address=JKanyomozi


I would like to change this URL to

http://www.example.com/JKanyomozi/music


I've only been able to do this by adding music as a parameter instead of adding it to the new URL as a prefix.
In short, i've turned this URL ...

http://www.example.com/artistmusic?address=JKanyomozi&req=music


... using this rule ...

RewriteRule ^([^/]*)/([^/]*)$ /artistmusic?address=$1&req=$2 [L]


... into ...

http://www.example.com/JKanyomozi/music


But the problem with this is that for other pages like the one for the videos, this rule redirects to the same page http://www.example.com/JKanyomozi/music instead of http://www.example.com/JKanyomozi/videos

The videos page's original URL is something like this ...

http://www.example.com/artistvideos?address=JKanyomozi


Which rule can I use to change the URL above to

http://www.example.com/JKanyomozi/videos


This applies for other pages like artistevents, artistphotos and artistbiography

Thank you in advance!

Answer

Try this :

RewriteRule ^([^/]*)/([^/]*)$ /artist$2?address=$1 [L]