Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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:

/our/example?this%123is%123a%123test

to:

/our/example?this%234is%234a%234test

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

 
discard

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