I spent all day yesterday struggling with Apache rewrite rules in an effort to make my old movable type urls work. Rewrite rules aren’t really the easiest things in the world and I was thinking that by now, someone would have written a javascript tool that let you paste in the urls you want to move from and to. Alas, I had to work it out myself using a combination of tips from a bunch of people.

Basically I wanted to change a url that had underscores and ended in php to have dashes and look like a folder – not a file. These are the magic lines:

# To handle old Movable Type permalinks.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*).php HTTP/ [NC]
RewriteRule ^(.*).php $1/ [R=301,L]

That takes a url like this:


and turns it in to this:


Not really understanding it too much, I think it just chops off the php part and then the other wordpress rewrite rules take over. This is what the entire wordpress section of the .htaccess file looks like:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# To handle old Movable Type permalinks.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*).php HTTP/ [NC]
RewriteRule ^(.*).php $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

I’ve put my wordpress admin stuff in a different directory without the php chopping rule so it’s not subject to the same rules here.

All this means that my old urls should still work. Hoorah!



Leave a Reply