how to rewrite '%25' in url

Posted by nn4l on Server Fault See other posts from Server Fault or by nn4l
Published on 2012-04-08T12:33:08Z Indexed on 2012/04/11 23:32 UTC
Read the original article Hit count: 232

Filed under:
|
|

My website software replaces space characters with '+' characters in the URL, A proper link would look like 'http://www.schirmacher.de/display/INFO/How+to+reattach+a+disk+to+XenServer' for example.

Some websites link to that article but somehow their embedded editor can't handle the encoding, so what I see in the httpd log files is actually

GET /display/INFO/How%2525252bto%2525252breattach%2525252ba%2525252bdisk%2525252bto%2525252bXenServer

which of course leads to a 404 error. It seems that the '+' character is encoded as '%2b' and then the '%' character is encoded as '%25' - several times.

Since there are many such references to different pages from different websites, I would like to rewrite the url so that the visitors get the correct page.

Here's my attempt which does not work:

RewriteRule ^(.*)%25(.*)$ $1%$2 [R=301]

What it is supposed to do is: take everything before the %25 string and everything after it, concat those strings with a '%' in between, then redirect.

With the example input URL the rule should rewrite to

/display/INFO/How%25252bto%2525252breattach%2525252ba%2525252bdisk%2525252bto%2525252bXenServer

followed by a redirect, then it should rewrite to

/display/INFO/How%252bto%2525252breattach%2525252ba%2525252bdisk%2525252bto%2525252bXenServer

and again to

/display/INFO/How%2bto%2525252breattach%2525252ba%2525252bdisk%2525252bto%2525252bXenServer

and so on. Finally, after a lot of redirects I should have left

/display/INFO/How%2bto%2breattach%2ba%2bdisk%2bto%2bXenServer

which is a valid url equivalent to /display/INFO/How+to+reattach+a+disk+to+XenServer.

My problem is that the expression does not match at all, so it does not even replace a single occurrence of %25.

I understand that there is a limit in the number of redirects and I should really use the [N] flag however I don't even get the first step right.

© Server Fault or respective owner

Related posts about mod-rewrite

Related posts about httpd