Phil Gyford


Sunday 9 March 2003

PreviousIndexNext 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 :)

Posted by Adam Lasnik on 10 March 2003, 12:07 pm | Link

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?

Posted by Becky on 26 January 2004, 1:08 am | Link

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.

Posted by Phil Gyford on 26 January 2004, 9:57 am | Link

Thanks, this worked for me.

Posted by David on 18 January 2006, 1:02 am | Link

Commenting is disabled on posts once they’re 30 days old.

Some sites linking to this entry (Trackbacks)

Search Engine Friendly URL's
Whew! I just completed a massive(for a non-techie like me) backend redesign on my blog to achieve ‘search engine-friendly URL’s on my blog and upgraded to MT 2.661. The result won’t be apparent unless you look close - so where...
At 'Jivha - the Tongue' on Wednesday 16 June 2004, 7:57 AM

Moving to Movable Type
Late last night, I finished doing an experimental [internal] port of my site over to Movable Type. I'd like to thank Brian Cantoni for his CityScript code frag that helped to bootstrap the process. Watch out for the fact that...
At '' on Friday 9 April 2004, 2:31 PM

Site updates
Summary of a bunch of site updates I've made recently.
At 'Becky's Journal' on Friday 13 February 2004, 6:14 PM

New File System
Well thanks to Phil Gyford, the archives now have a new easier to read structure. Gone are the non-descript numeric URLs like
At 'Dave's Rants' on Thursday 13 November 2003, 11:36 PM

The slightly more astute/anal/bored among you will have noticed that the individual entry archives have now moved from Movable Type's...
At 'ext|circ' on Wednesday 13 August 2003, 12:07 AM

Movable Type Tips and Tricks
So that I never lose them again, I list here, without comment and in no partiuclar order, a variety of
At 'WOIFM :: An Institute of Higher Learning' on Tuesday 25 March 2003, 3:22 AM