August 23, 2008

A [W3C] Cool Way to Switch MT Blog Posts from ID-based to Title-based URLs

I finally got enough time to research and work through the detailed steps for switching my Movable Type configuration for this blog over from using entry URLs with entry ID-numbers (eg. /weblog/archives/2008/07/000502.html) to using entry URLs based on entry titles (eg. /weblog/archives/2008/07/managing_and_motivating_developers.html)

There are some neat tricks on how to do this cleanly using URL redirects while keeping your W3C coolness.

In the beginning of the blogosphere (circa Movable Type v1.0) the default configuration for MT blogs was to use entry URLs with entry ID-numbers (eg. http://www.thearchitect.co.uk/weblog/archives/2008/07/000502.html)

Somewhere along the way, we bloggers learned that more "human-friendly" URLs were better (not least because of the beneficial effect on search engine rankings!) - so blogs started using entry URLs based on entry titles (eg. http://www.thearchitect.co.uk/weblog/archives/2008/07/managing_and_motivating_developers.html)

Well, I'm a big believer in web pages / resources having "cool URI's" [W3C - Cool URI's don't change] as I've pointed out many times before, so I've held off on changing URLs on this blog until I had guaranteed way to maintain backward compatibility with the original URLs.

I finally got enough spare time to research and work through the detailed steps for switching my Movable Type (MT) blog configuration over to using title-based URLs while getting MT to create the necessary URL Redirects declarations for Apache to keep the old URLs "cool" for nearly 500 posts (not something I wanted to do by hand!) and avoid creating "linkrot" (which is something I really hate on the Web - and sadly Microsoft/MSDN is still one of the worst culprits!).

Any URL that has ever been exposed to the Internet should live forever: never let any URL die since doing so means that other sites that link to you will experience linkrot.

[Jakob Nielsen - Fighting Linkrot]

So here's a little trick for creating the necessary Apache Redirect entries for all your existing weblog posts.

In the MT Admin app, create a new Index Template:

Template Name = Redirect List
Output File = redirects.txt
Rebuild this template automatically when rebuilding index templates = True
Template Body =

<MTEntries lastn="1000000">
Redirect permanent /weblog/archives/<MTEntryDate format="%Y/%m">/<MTEntryID pad="1">.html <MTEntryLink>
</MTEntries>

Then, when you click "Save and Rebuild" a file will be created with the necessary Apache server Redirect declarations for all your old entries to map to their new location URLs - for example (all on one line):

Redirect permanent /weblog/archives/2008/07/000502.html 
http://www.thearchitect.co.uk/weblog/archives/2008/07/managing_and_motivating_developers.html

Now just copy the contents of the generated file into your httpd.conf or .htaccess file, restart the Apache server processes, and your blog will be cool again! :-)

Entry categories: Weblog
Posted by Jorgen Thelin at August 23, 2008 10:00 AM - [PermaLink]