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

I need to rewrite a URL that contains one or more strings of characters incling a % character (for instance %123) into another string of characters including a % character (for instance %234).

I am able to do this using the special THE_REQUEST attribute with something like this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\%123(.*)\ HTTP
RewriteRule .* /%1\%234%2 [R,NE]

However, this does not work for URLs that contain more than one "%123" strings... The N option has no efect as it seems that the value of THE_REQUEST is not changed.

Any ideas?

share|improve this question

From what I can tell you can only perform the substitutes in the QUERY_STRING part of the request. So:

RewriteCond %{QUERY_STRING} ^(.*\%)123(.*)$
RewriteRule ^(.*)$ $1?%1234%2 [NE,N]

Will rewrite a URL like:




However, there is no way to perform this type of substitution for the REQUEST_URI part of the query. By the time mod_rewrite receives the REQUEST_URI all the percent marks have been converted. For example, if the REQUEST_URI contained %12 it appears to mod_rewrite as control-R (0x12) and there does not seem to be any way of matching non-ASCII characters in mod_rewrite.

share|improve this answer

Your Answer


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