Forum Moderators: phranque

Message Too Old, No Replies

301 redirect for URL with "special" characters.

Can't figure out how.

         

Broadway

4:55 am on Jul 14, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been going through my 404 data in Webmaster Tools.
It says I have websites linking in using URL's that contain the following types of syntax.

page.htm%2523references
page.htm%23top.posts
page.htm%C2%A0

I've been unsuccessful in creating 301 redirects for these links in the form:
redirect 301 \page.htm%C2%A0 http://www.example.com/page.htm

I seem to struggle with .htaccess in general.
Could someone point me toward the proper syntax that's needed (the way to handle the special characters)?
Or possibly you have to rewrite the URL (to get rid of the characters) before you can redirect it?
Thanks.

lucy24

6:14 am on Jul 14, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First: Do you have any existing redirects that use mod_rewrite (any directive beginning in RewriteBlahblah)? If yes, you will need to redo your rules in mod_rewrite. Otherwise you can stick with mod_alias, but you're going to change to RedirectMatch so you can do everything in a single rule. Try this:
RedirectMatch 301 ^/(.+\.htm). http://www.example.com/$1
See the . dot after the ".htm"? That means "any character at all after the "htm" extension. All you're doing is redirecting URLs with any extraneous stuff to the without-extra-stuff form. You don't even need to figure out whether they're reaching your server as %C2 or  or whatever it may be.

If none of your URLs ever contain literal periods, change the pattern to
^/([^.]+\.htm).
I assume you've already checked to make sure the bad characters aren't coming from typos on your own site.

redirect 301 \page

Is the backslash a typo?

Then again... If they're not your own links, and they're not coming from some other site that's valuable to you (apart from not being able to type), you might just let the 404s fall where they may. It's not necessarily your problem.

Uh.... Does the pattern of a RedirectMatch start with a slash? I forget. It's been a while.