Movable Type to WordPress, Part 3

The first two parts of this blog’s odyssey from Movable Type to WordPress can be found here and here. The first part discussed the reasoning behind the move, and the second dealt with problems that arise when importing of Markdown-formatted posts into WordPress. Today, I’ll discuss the differences in permalinks between Movable Type and WordPress and how I got my old permalinks working with the new system.

I had my permalinks in Movable Type linked to the monthly archives (I think this is the default, but I don’t remember and can’t go back to find out for sure). So the MT permalink for this post, for example, would be

The default permalink format for WordPress is based on the post number, so the WP permalink for this post would be

which is certainly more succinct but doesn’t say much about the content of the post.

Fortunately, you can change the format of WordPress permalinks by going to the Permalinks Options page. I changed the format to better match my old Movable Type permalinks by choosing a custom structure of /%year%/%monthnum%/%postname%/.

After this change, the WordPress permalink for this post will be

The only difference between this and my old Movable Type format is that this has a slash after the title, while the MT link has “.html” after the title.

Getting my new permalinks to match up reasonably well with my old permalinks was not just a matter of aesthetics. Many of my older posts have links to other posts within the blog, and there are links to my older posts at other sites. All of these links will be broken if I don’t take some action. I decided to handle the internal and external links differently:

Editing internal permalinks in over 300 posts sounds like a terrible job, but because I chose the new permalink format to be very close to the older format, the task was really simple. First, I did all the editing in the text file of exported posts from Movable Type before importing them into WordPress (I talked about the MT export file in Part 2 of this series). Editing a single text file that’s sitting on my local computer is much easier than editing hundreds of individual database entries on a remote computer. The necessary change was a simple find-and-replace using regular expressions. The find string was


and the replace string was


The “www.” part was an option in the find string because I learned that I had left it out of some internal links.

External permalinks were a bit more difficult. These have to get changed on the fly by my webhost’s Apache server using directives in a special file called “.htaccess” stored at the root directory of the blog. The difficulty came not because the regular expressions for rewriting are more complicated, but because I’m not familiar with the other aspects of Apache’s rewrite rules. After much trial and error, the .htaccess file for the blog now looks like this:

 1:  <IfModule mod_rewrite.c>
 2:  RewriteEngine On
 3:  RewriteBase /all-this
 5:  # To handle the old MovableType feeds.
 6:  RewriteRule ^atom\.xml$ feed/atom/ [R,L]
 7:  RewriteRule ^index\.xml$ feed/ [R,L]
 9:  # To handle old Movable Type permalinks.
10:  RewriteRule ^([0-9]{4}/[0-9]{2}/.*)\.html$ $1/ [R,L]
12:  # From WordPress, to allow named permalinks.
13:  RewriteCond %{REQUEST_FILENAME} !-f
14:  RewriteCond %{REQUEST_FILENAME} !-d
15:  RewriteRule . /all-this/index.php [L]
17:  </IfModule>

Lines 1-3, 13-15, and 17 were added by WordPress itself when I changed the permalink structure. Lines 5-7 and 9-10 are my insertions. My part and the WordPress part are mixed together because my lines had to be placed after the RewriteEngine and RewriteBase lines and before the RewriteCond lines.

The line for handling permlinks is Line 10, with the search and replace strings very much like what I’ve given above. It was the “[R,L]” option set at the end of the line that took me a while to figure out. And although it works, it still may not be the best way to handle the rewrites.

Shortly after fixing the permalinks, I realized that my RSS feeds had also changed, and that anyone using the old feed URLs would see no updates. Lines 6 and 7 rewrite the Atom and RSS2 feeds from the Movable Type format to the WordPress format.

I believe my next post will cover what I promised last time: the blog’s template and CSS files.