Page is a not externally linkable
sublime1 - 2:21 am on Nov 13, 2010 (gmt 0)
madmatt69 --
Sorry this one took so long to get to. In your example, the URL has an actual space character, but I think depending on the browser, requesting the link, it could get turned into a + or a %20, both valid escapes for a space character.
If you can do this in PHP, the code is simple:, e.g.
<?php
$str = " fo o+bar%20fubar ";
$str = preg_replace('/(%20|\s|\+)/', '', $str);
// will print "foobarfubar"
echo $str;
?>
So early in your request chain, you would do this:
<?php
// get the path part of the request
$str = $_SERVER['REQUEST_URI'];
// remove all the characters you don't want
$str = preg_replace('/(%20|\s|\+)/', '', $str);
// if anything changed
if ($str != $_SERVER['REQUEST_URI']) {
// return a 301
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://example.com." . $str );
}
?>
It's far more difficult using RewriteRule in your apache conf file because of the lack of a repetition operator.
Tom