3

I have following rule:

RewriteCond %{QUERY_STRING} ^products=Product Name$
RewriteRule ^buyonline\.php$ http://www.example.com/shop/5-Product-Name.html? [L,R=301]

I need to redirect links existing in Google already, however there is no pattern so I can't just use e.g. ^products=(.*)$.

Code above works fine if parameter has no spaces. I have tried lots of combinations like \s doublequotes, etc, etc.

anubhava
  • 761,203
  • 64
  • 569
  • 643
Janusz Kubala
  • 401
  • 1
  • 5
  • 18
  • Most likely the space character will be encoded when the request reaches your server, so try using `%20` in its place. – CBroe Aug 14 '13 at 14:14

1 Answers1

3

Space is transmitted as %20 to Apache server and % needs to be escaped as well.

This should work:

RewriteCond %{QUERY_STRING} ^products=Product\%20Name$
RewriteRule ^buyonline\.php$ http://www.example.com/shop/5-Product-Name.html? [L,R=301]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    I needed to use the regex whitespace character `\s` for matching what I would expect to be a space after MSIE in this user agent test: `RewriteCond %{HTTP_USER_AGENT} ^.*MSIE\s[67](?!.*Trident[1-9]).*$` – Sam May 16 '14 at 14:21
  • Try this: `RewriteCond %{HTTP_USER_AGENT} "^.*MSIE [67](?!.*Trident[1-9]).*$"` – anubhava May 16 '14 at 14:42