Forum Moderators: phranque

Message Too Old, No Replies

301 redirect URLs containing percent-encoded characters

Trying to figure out .htaccess redirect

         

camscool

3:08 pm on May 7, 2009 (gmt 0)

10+ Year Member



In working with Google Webmaster Tools, we received a 404 link that reads like this.

[mysite.com...]

I have tried several ways to rewrite the rule, but none seem to be working. I know that my problem is the '%' symbols in the code. I dunno why a website linking to us has such a weird url. We have nothing like this on our site.

My questions is how to code this in the .htaccess and just redirect this to the homepage.

Any help? Thanks

Cam

jdMorgan

3:46 pm on May 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is likely the result of a cut-and-paste from a UTF-encoded page into links on the pages you see linking to you like this. You'll also often see strange links with commas and periods at the end of the URL due to auto-linked URLs in sentences written on forums and blogs -- The poorly-implemented auto-linkers include the sentence punctuation in the URL itaelf!

Please post your best-effort code as a basis for focused discussion.

Thanks,
Jim

camscool

4:07 pm on May 7, 2009 (gmt 0)

10+ Year Member



I tried a simple redirect like:

Redirect 301 /%C2%A0 http://www.example.com/
(That of course didn't work)

I tried "" marks like you do with a URL with spaces/%20's in them.

Redirect 301 /"%C2%A0" http://www.example.com/

I also tried a number of different RewriteRules.

RewriteCond %{REQUEST_URI} !\/^%C2%A0\$ [NC]
RewriteRule ^%C2%A0$ http://www.example.com/ [R=301,L]

These are some of my examples. I am completely off aren't I?

[edited by: jdMorgan at 7:21 pm (utc) on May 7, 2009]
[edit reason] example.com [/edit]

jdMorgan

7:21 pm on May 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this instead:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^%?\ ]*\%
RewriteRule ^. http://www.example.com/ [R=301,L]

Here, we examine the original (possibly-encoded) client request instead of the un-encoded REQUEST_URI

Jim

camscool

7:27 pm on May 7, 2009 (gmt 0)

10+ Year Member



Thanks Jim,

Worked like A charm. You are seriosuly the .htaccess guru

Cam