Extensionless URIs in Movable Type 4

March 30, 2008

There will be many new web standards in the future, but we don’t want our URIs to break or appear outdated when that happens. In Movable Type 4, it’s possible to keep the same URI while hiding the underlying technology (or allowing for multiple formats) is to place each document at a folder and use Apache’s MultiViews to serve up the correct file. Furthermore, when serving XHTML you may wish to store everything on the filesystem as such. The default path for a story is myblog.com/2007/10/story.html. What we want instead is for the content to be stored as myblog.com/2007/10/story/index.xhtml and accessed at myblog.com/2007/10/story/. Similarly, we will need to adjust the default /archives.html and /index.html paths. I actually want /archives/ to point to the archive index, and for individual yearly, monthly, and individual archives to be contained within /archives/. Regardless of the specific structure you prefer, here’s how to proceed.

First, visit Blog Settings | Publish and change the default archive extension to .xhtml. Skip this step unless you have a specific reason for serving files to browsers as application/xhtml+xml (for example, when serving XHTML+MathML). Then, edit the various archive mappings for Entries (see Design | Templates | Archive Templates). For example, I changed the default Entry mapping from %y/%m/%-f (corresponding to yyyy/mm/entry-basename.xhtml) to archives/%y/%m/%-b/%i (corresponding to yyyy/mm/entry-basename/index.xhtml). This way, index.xhtml will be appended to every Entry archive page. I made similar modifications to the Entry Listing and Page archive mappings (the default mappings are probably okay unless you want to change their location, as I did, since they already end with the %i file path specifier). Then, modify the output filenames for the Archive Index and Main Index templates to archives/index.xhtml and index.xhtml respectively.

If you do change the file extension, you will probably also need to add something like the following to your .htaccess file, so that index.xhtml will have priority over index.html:

DirectoryIndex index.xhtml index.html

This all has the added benefit of serving everything as application/xhtml+xml by default, due to the file extension. We can thus simplify our .htaccess file, only adding browsers that we know need files to be served as text/html.