Search code examples
apache.htaccessmod-rewrite

'%2' being stripped on RewriteRule


I have rules on .htaccess that looks like this:

RewriteCond %{REQUEST_URI} ^/services/service1/?$
RewriteRule . http://www.domain.com/Service1%20Services.html [R=301,L]

but the %2 is being stripped and the end result is http://www.domain.com/Service10Services.html

I have searched and found that %2, just like %1 is a RewriteCond Backreference.

My problem is I don't know how to escape it so that it would be treated as a string literal. Can someone please tell me how am I supposed to do this?


Solution

  • %2 is a special back-reference variable, you need to escape it to use it literally. Also you need NE flag for non encoding.

    Use this rule:

    RewriteRule ^services/service1/?$ http://www.example.com/Service1\%20Services.html [R=301,L,NE]