How I Remapped My Permalinks
Thursday, March 31st, 2005One of the biggest things that prevented me from moving to WordPress for a long time was the fact that if I switched, all of my permalinks would break. Fortunately, I came up with a good way of remapping every one them using a combination of Marc Nozell’s Blosxom to Wordpress migration tutorial, htaccess, and some code extracted from the Wordpress Moveable Type import utility. Here’s how I did it.
To start, I modified Nozell’s templates, which cause Blosxom to dump the weblog’s content in the standard Moveable Type export format, to include an additional “permalink” field for each post. I did this by simply adding the following to his story.mt template:
PERMALINK: /weblog$path/$fn.html
I then exported all of my Blosxom posts using this template, as described by Nozell.
Next, I extracted just the code that parses the Moveable Type export files from the Wordpress Moveable Type import utility (in “import-mt.php” under the “wp-admin” directory), put it into a separate file (which I call “import-generate-htaccess.php“), added a bit of code to extract the new permalink field from each post, and then put in a line to output mod_rewrite directives that map the old permalink to the new one based on that information:
print "RewriteRule ".$permalink." http://weblog.scifihifi.com/".$post_date."/".$post_name."\n";
When this code is run on the MT Export file Bloxom generates (by going to “wp-admin/import-generate-htaccess.php in your browser), it dumps to the browser a mapping between your old post URLs to your new ones. Simply put these rewrite directives in an htaccess file at the root of your old weblog (making sure to enable rewrites first in the file), and voila: your old permalinks now redirect to your new ones.
This way of doing things is very hacky, of course, and the actual steps involved will differ a lot depending on peoples’ setups. I thought I’d at least share the general idea, though, in case someone else is in the same boat.