Mod_rewrite and escaped / (%2f) in query string

apache-2.2mod-rewrite

I want to redirect the following url

oldsite.com/index.htm?Page?somepath%2fsomefile

to

newsite.com/productindex.htm?p=somepath%2fsomefile

I have the following rules

RewriteCond %{QUERY_STRING} ^Page=(.*)$
RewriteRule ^index.htm$ http://newsite.com?p=%1 [R=301,NC,L]

But it redirects to

newsite.com/productindex.htm?p=somepath%252Fsomefile
>--------------------------------------^^^^^

There are a lot of references about a long standing bug with double escaping that was recently fixed (2.2.12 I think) and as I am running 2.2.9 I thought the RewriteRule B flag may help, but it makes it worse…

newsite.com/productindex.htm?p=somepath%25252Fsomefile
>--------------------------------------^^^^^^^

Any ideas from the Apache gurus?

Best Answer

Its the NE (No Escape) flag that I need

RewriteCond %{QUERY_STRING} ^Page=(.*)$
RewriteRule ^index.htm$ http://newsite.com?p=%1 [R=301,NC,L,NE]
Related Topic