Monday, August 15, 2016

apache 2.2 - mod_rewrite and escaped / (%2f) in query string



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?


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]

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...