Changing Movable Type archive URLs

I’ve wanted to change the way Movable Type generates the URLs for Individual archive pages for some time. Although I was pleased with the dated directories, the numbered file was ugly and meaningless (eg, /phil/writing/2003/03/07/000456.php) unlike, for example, Tom’s sensibly named files. But I didn’t relish manually creating a .htaccess file to redirect users from the old URLs to the new pages.

Then I realised Movable Type can do all the hard work. I just had to create an index template, the output of which I could paste into my .htaccess file. Here’s my template:

<MTEntries sort_order="ascend">
redirect /phil/writing/<$MTArchiveDate format="%Y/%m/%d/"$><$MTEntryID pad="1"$>.php<$MTArchiveDate format="%Y/%m/%d/"$><$MTEntryTitle dirify="1" trim_to="16"$>.php

It’s not too clear on this web page, but between the opening and closing MTEntries tags there is a single long line. When you rebuild the template you’ll have created a file each line of which looks something like this:

redirect /phil/writing/2003/03/07/000456.php road_geeks.php

Paste this into your .htaccess file, but don’t save it yet. Go to Weblog Config > Archiving and change the Archive File Template for your Individual archive to the new method. Rebuild your site. Save the .htaccess file. That’s it, and you can now remove that temporary index template.

There’s no real need to delete the old Individual archives as users will always be redirected before acessing them. But if you like to keep things tidy you could use a similar index template to create lines you could paste onto a command line to rm the old Individual archives. Or, if you’re feeling even more reckless, delete all of your archives before rebuilding with the new style URLs.

By the way, I limited the length of my filenames to 16 characters so each complete URL fits onto a line of forwarded email without breaking. Oh, and, of course, make sure you can use .htaccess redirects on your server before you start all this!


  • Or you could use the amazingly cool (and free) Apache Guardian software ( to do the same thing and much more.

    With AG, you can use regular expressions to redirect anything to anything else… with a permanent redirect, temporary redirect, or one of many other options.

    It’s an indispensible program in my Webmaster arsenal :)

  • I decided on this method — feel special, there’s about a gazillion crazy hard-to-understand methods out there, and yours is by far the easiest to understand.

    Unfortunately… it’s not working, and I’m quite sure it’s my fault, but am hoping you’d have mercy on me and throw me a bone anyway. :)

    My .htaccess _looks_ right, in my uneducated opinion, but it’s not even redirecting links I’ve posted to certain pages all on my own site. All the old pages are still on the server, as are the new ones. So my thoughts, off the top of my head…

    1) Does the .htacess file have to be in the root of the domain? Currently it’s in a subdirectory.

    2) Do I need to do any chmod wizardry to .htacess after uploading it?

    3) Are there any favors (sexual or otherwise ::wink::) I could offer to get you to help out with my quandary?

  • To answer your questions:

    1) The .htaccess file should affect all files (or the locations where files used to be) ‘beneath’ it. So, assuming the directory structure of your site is still pretty much the same, it should be in /journal/archives/ , or higher up in the structure.

    2) .htaccess is just a text file, so I don’t think it needs any particular permissions.

    3) No favours required, but I’m happy to help more if I can.

    One problem might be that your domain needs to be allowed to do redirects - ISPs tend to restrict what you’re allowed to do, and redirects aren’t always one of them.

  • Thanks, this worked for me.