1

I have this URL:

oldsite.com/profile.php?uid=10

I would like to rewrite it to:

newsite.com/utenti/10

How can I do that?

I wrote this:

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$
RewriteRule ^profile\.php$ http://www.newsite.com/utenti/$1 [R=301,L]

But $1 match the full query string and not just the user id.

1

"$1" matches the first pair of brackets on the same line (the RewriteRule); you need "%1", which matches the first pair of brackets on the /previous/ line - the RewriteCond:

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$
RewriteRule ^profile\.php$ http://www.newsite.com/utenti/%1 [R=301,L]

A better way would be to do it with only 1 line (a RewriteRule), but you can't do that if the uid is in the QueryString.

0
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{SERVER_NAME} ^oldsite.com$
        RewriteCond %{QUERY_STRING} uid=([0-9]+)
        RewriteRule ^/profile\.php http://newsite.com/utenti/%1 [NC,R=301,L]
</IfModule>

the point is to use %1, not $1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.