How I got rid of MT numbered entries

Sausages, laws, and websites -- most people don't want really want to know how they're made. So feel free to turn your head away now.

I've been using Movable Type as my blogging engine since 1999 and, even though I'm using the latest version of the software, I've still got a lot of legacy cruft throughout my sites. For example, the individual posts of FuzzyCo and the New Improv Page are all just numbers (technically, "padded entry IDs"), like 001883.html. It's ugly, it doesn't tell you anything about the post, and it's depreciated by search engines. So I wanted to switch to a more modern system, where the above post would be a slightly more readable how_i_got_rid_of_mt_numbered_e.html.

It's easy enough to just change a setting in Movable Type and rebuild the site using new name styles, but I also didn't want to break links people (including myself) have made to old entires. There's a oft-linked solution to embed the old entry names in the entry basename, so that old entries would keep their numbered names through rebuilds and new entries would get new names. But there are two problems with this: 1) I don't want the old entries to stay ugly -- I want those numbered names to be gone, daddy, gone and 2) I understand that there limitations (bugs, even) in how MT handles customized entry basenames. What to do? htaccess! An htaccess file can (among other things) tell a webserver to redirect one filename to another and I could use a similar technique to the name-remapping solution linked above to automatically generate (most of) an htaccess file.

Order is somewhat important here, so here's the steps I went through:

1. Backup your Movable Type database. Always, always backup before you do any big changes. Backup all the time, anyway.

2. I made a new index template called "redirect" (I could have named it "htaccess", but I wanted to have to manually rename it when I was ready to put it into place, to have that degree of control).

That template contained the following:

<MTEntries lastn="99999"$>
Redirect 301 /archives/<$MTEntryID pad="6">.html<$MTEntryCategory dirify="1">/<$MTEntryBasename$>.html

(The middle part from "Redirect" to the second ".html" should be one long line, with no line break.)

To break this down, <MTEntries lastn="99999"$> says "do this for the last 99,999 entries". (If you have more entries than that, you'll need to adjust. Also, hats off to you.) Redirect means redirect any request for the listed file to the listed URL. 301 is a code that tells the requesting browser that this is a permanent change (302 is temporary) and search engines and well-behaved web services will update their databases, bookmarks, etc. /archives/<$MTEntryID pad="6">.html generates the current file name (the entryID, padded with zeros to make a 6 character string) (your file path may, of course, vary).<$MTEntryCategory dirify="1">/<$MTEntryBasename$>.html generates where the new file name is going to live. I'm switching to "primary_category/entry_basename.html", so your code may vary if you're switching to a different scheme.

3. Save and rebuild the template. Note where the file is generated.

4. Go to Settings >> Publishing and under Archive Mapping change the Individual Entry Archive to use your chosen naming scheme. Save changes. (If, like me, you're doing this because you've been using MT for a long time, you may want to go to Settings >> New Entry Defaults and change Basename Length up from the old default of 15 to the new default of 30.) Rebuild your site. Check that everything is working with the new naming scheme.

5. When you're sure everything is working, move/rename the redirect file to .htaccess (the leading dot is important). Don't replace any exisiting .htaccess file! The possible complexities of your local web setup are beyond the scope of this post. (Have I disclaimed enough?)

(I also changed my Category and Date-based Archive name schemes at the same time, but there were so relatively few of them that I just constructed the htaccess entries with some simple grepping in BBedit. I suppose it'd be possible to do something similar to the above for them as well, though.)

I've only made the change to the New Improv Page so far, and I'm going to pound on it for a few days to make sure there isn't anything I've missed before I change over FuzzyCo, but I thought this method was worth sharing.