1

Someone linked to my site from nice place but the moron type the wrong URL, he did %20 at the end of it (probably his site did that). So I want to redirect http://example.com/%20 to http://example.com, because http://example.com/%20 is of course going to http://example.com/404 cuz that one is not valid URL.

I tried this:

rewriterule ^%20(.*)$ http://example.com$1 [r=301,nc]

But it just doesn't work. Looks like the % character has to be somehow escaped or something. So i tried also

rewriterule ^\%20(.*)$ http://example.com$1 [r=301,nc]

to give the % its original meaning by escaping it but it doesn't seem to be working either. Also read htaccess to escape percent (%) from URL but the solution presented there doens't seem to be working either. Anyone has idea how to do this? Thanks so much.

Community
  • 1
  • 1
Mordor
  • 485
  • 2
  • 4
  • 14

1 Answers1

2

You can match %20 in RewriteRule using \x20:

RewriteRule ^\x20(.*)$ /$1 [R=301,L,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643