Skip to content
Advertisement

htaccess redirect profile page

I’m creating a system which shows your profile if you visit http://example.com/profile/profile.php?username=test

I would like to make it so you could go to http://example.com/profile/test and it would still work. At the same time I would like it to show ^^ as the url if you visit http://example.com/profile/profile.php?username=test

How can this be done?

Advertisement

Answer

This should do :

RewriteEngine on
RewriteRule ^profile/(.*)$ http://example.com/profile/profile.php?username=$1 [L]

You want to match everything after profile/ to the end of URI, and then pass it as parameter value to your “real” URI.

[L] flag may not be necessary, it indicates the rewrite engine you’re done and it does not have to go throught the next rules.

You can try it here

Edit : I just see @Peter’s comment, you definitively should read the question he linked, it will help you understand the whole thing.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement