tags:

views:

201

answers:

4

How would I rewrite:

http://localhost/profile.php?user=MaFi

to

http://localhost/user/MaFi
+1  A: 

Try a RewriteRule like this:

RewriteRule ^profile.php?user=(.*)$ /user/$1      [R=301,L]
zombat
This just won’t work as the query is not URI part of the URI path.
Gumbo
Hmm... I thought for sure that worked, but further research proves me wrong. @Mafioso - Gumbo is correct, this rule will not give you the expected results. You should go with his answer. I can't delete this one until it is unaccepted.
zombat
+2  A: 

If you really want to redirect /profile.php?user=MaFi to /user/MaFi, try this rule:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)user=([^&]+)(&+(.*))?$
RewriteRule ^profile\.php$ /user/%3?%1%5 [L,R=301]

But if actually you want to rewrite /user/MaFi internally to /profile.php?user=MaFi, try this rule:

RewriteRule ^user/([^/]+)$ profile.php?user=$1 [L]
Gumbo
A: 

Gumbo your second code works for me but i need to change: http://server.com/profile.php?user=MaFi to http://server.com/MaFi

any idea?

greenbandit
A: 

yoursite.com/MaFi ~ yoursite.com/profile.php?user=MaFi

<a href='/MaFi'>MaFi</a>

RewriteRule ^([^.]+)$ "/profile.php?user=$1" [L]

Or maybe...

yoursite.com/profile.php?user=MaFi ~ yoursite.com/MaFi

<a href='/profile.php?user=MaFi'>MaFi</a>

RewriteCond %{QUERY_STRING} user=(.+)
RewriteRule ^([^.]+)$ "/%1" [QSA]

I'm not 100% on these but hopefully they help.

Natrix