How can I redirect a URL with the following special characters:
http://www.example.com/%C2%A0
I have tried the following in the .htaccess file:
Redirect /%C2%A0 /
lucy24
7:22 am on Apr 19, 2012 (gmt 0)
... and then what?
Wait. Never mind. Did you say %A0 ? ? ?
That's the non-breaking space. Either A-circumflex + nbsp, or nbsp by itself, depending on what file encoding you're in.
What the bleepity bleep is a non-breaking space doing in your URL in the first place? Please say you're talking about a "salvage redirect" necessitated by a typo that you've now fixed.
Does your existing htaccess contain any rules using mod_alias (Redirect by that name), mod_rewrite (RewriteRule), or both? This will determine which module you use for making your Redirect. It can be done either way.
OK, now then... What happens with
Redirect /%C2%A0 /
? The syntax isn't ideal, but it should work. That's assuming the %C2%A0 has landed on your server in that form instead of in " " decoded form.
What's with this sudden flurry of servers refusing to decode percent-encoded URLs? Do they think we have nothing better to do than write code?
nakita_dog
12:02 pm on Apr 19, 2012 (gmt 0)
In the end I solved the problem through a custom 404 error page. I basically did the following:
<?php $url = $_SERVER['REQUEST_URI'];
if (false !== strpos($url,'%C2%A0')) { //echo "Here1 = ".$url; Header("HTTP/1.1 301 Moved Permanently"); Header("Location: http://www.example.com"); } else { header('HTTP/1.0 404 Not Found'); echo "<h1>404 Not Found</h1>"; echo "The page that you have requested could not be found.<br>"; echo "<a href='http://www.example.com'>http://www.example.com</a>"; exit(); }
?>
g1smd
1:26 pm on Apr 23, 2012 (gmt 0)
When you redirect to the root page of a site, the correct URL ends with a trailing slash: www.example.com/
Your RewriteRule might have worked if you had escaped the percent sign. Don't use Redirect, use a RewriteRule configured as a redirect.