Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have this URL:

I would like to rewrite it to:

How can I do that?

I wrote this:

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$
RewriteRule ^profile\.php$$1 [R=301,L]

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

"$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$ [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.

share|improve this answer
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{SERVER_NAME} ^$
        RewriteCond %{QUERY_STRING} uid=([0-9]+)
        RewriteRule ^/profile\.php [NC,R=301,L]

the point is to use %1, not $1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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