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.

2 Answers 2

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.