How to detect requests to old Movable Type-created pages

| 0 Comments
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'};
$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);
    }
}
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.

Leave a comment

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Recent Entries

Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…
Progress of a different sort
You know we have reached a level of decadence seldom seen in the history of the West when our women…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID