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:
redirect /phil/writing/<$MTArchiveDate format="%Y/%m/%d/"$><$MTEntryID pad="1"$>.php http://www.gyford.com/phil/writing/<$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 http://www.gyford.com/phil/writing/2003/03/07/ 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!