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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have just made a new website for a client and for SEO purposes have a HUGE urlmap setup to rewrite the old site URLs to relevant places on the new site.

Technical details are:

CentOS 5.6 
Apache 2.2
PHP 5.3.8

Here is the mod_rewrite block:

RewriteMap urls txt:/www/sites/
RewriteCond %{REQUEST_URI}      ^(.*)$
RewriteCond ${urls:%1|NONE} ^(.*)?$
RewriteCond %1  !NONE
RewriteRule .*  %1 [R=301,NS,QSA,L]

Some redirects do work, for example: redirects correctly. does not, and 404s. The only difference here is the "+" symbols. This doesn't appear in the rewrite log either, like it's being completely passed over by mod_rewrite due to the special characters.

Another odd occurrence is, for example: - doesn't rewrite properly, looking in the Apache rewrite log it's completely ignoring the query "?catid=3" for some reason.

I am no expert on mod_rewrite so would appreciate any assistance. If you need more information please do ask.

Thanks in advance!


Fixed with:

RewriteCond %{REQUEST_URI}\?%{QUERY_STRING}  ^(.*)$
RewriteCond ${urls:%1|NONE} ^(.*)$
RewriteCond %1  !NONE
RewriteRule .*  %1? [R=301,NS,L]
share|improve this question
RewriteRule pattern (and %{REQUEST_URI} variable) can ONLY match path part of the URL. To match query string you have to use RewriteCond %{QUERY_STRING} YOUR_PATTERN_HERE. For special characters -- try using [B] flag: – LazyOne Sep 21 '11 at 13:22
Thanks for that. Got it going with an additional rule which I've added as an edit to my question. – djk Sep 23 '11 at 15:05
Feel free to post your solution as an answer and accept it. – quanta Sep 23 '11 at 16:26
Please post your solution as an answer and accept it, so others can stop reading the full question before realizing it's been answered. – xofer Sep 23 '11 at 17:44
up vote 0 down vote accepted

Fixed with:

RewriteCond %{REQUEST_URI}\?%{QUERY_STRING}  ^(.*)$
RewriteCond ${urls:%1|NONE} ^(.*)$
RewriteCond %1  !NONE
RewriteRule .*  %1? [R=301,NS,L]

Thanks guys.

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.