Movable Type used underscores in the past to represent spaces in file names. For example, hello_word.html instead of hello-world.html. If you create an Apache error handler in PHP, you can use the following code sample to redirect from the old style to the new style without any problems:
$str = $_SERVER{'REQUEST_URI'};That will convert a request for, say, http://www.domain.com/2008/11/hello_world.php into http://www.domain.com/2008/11/hello-world.php. I'm using that now in my HTTP error handler.
$matches = array();
if (preg_match("/\/[\d]+\/[\d]+\/([\w]+_)+[\w]+\.(html|php)/", $str, $matches))
{
$filename = str_replace("_", "-", $matches[0]);
if (file_exists("." . $filename))
{
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '. "http://www.codemonkeyramblings.com" . $filename);
}
}
Leave a comment