3

I've come across similar questions, such as this one, and found similar instructions on mod_rewrite tutorials.

I've determined that I need something along the lines of

RewriteRule ^(.*)<(.*)$ /$1$2 [L,R=301]
RewriteRule ^(.*)>(.*)$ /$1$2 [L,R=301]

This works for http://domain.com/<>, but it does not work for http://domain.com?a=<>

I've also added the following, in my attempts to remove these characters from the query string:

RewriteCond %{QUERY_STRING} ^(.*)<(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]
RewriteCond %{QUERY_STRING} ^(.*)>(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]

This did not change anything. I've also tried escaping < and > in the regex as well (i.e. ^(.*)\<(.*)$).

The end result that I am trying to achieve is to have

http://domain.com/<whatever> turn into http://domain.com/whatever, and

http://domain.com/a=<whatever>&b=whatever turn into http://domain.com/a=whatever&b=whatever

Community
  • 1
  • 1
jperezov
  • 3,041
  • 1
  • 20
  • 36

1 Answers1

2

< is encoded as %3C and > is encoded as %3E by browsers. So have your rules like this:

RewriteCond %{QUERY_STRING} ^(.*?)(?:%3C|%3E)(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=302,NE]

This will redirect http://domain.com/?a=<whatever>&b=whatever to http://domain.com/?a=whatever&b=whatever

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I could've sworn that encoding happened _after_ the .htaccess was taken into account. Good to know that this isn't the case on RewriteCond (or is it just with the query string?) – jperezov Oct 17 '14 at 15:04
  • 3
    Yes i believe it is case only with query string. – anubhava Oct 17 '14 at 15:06
  • 1
    Perfect answer! Learned something new today about the query string encoding timing. Thanks! – Concept211 Jun 22 '17 at 09:55