Walking

Wait a minute. I remember asking about this. Ian actually advocates against using application/xhtml+xml for XHTML pages; instead, he supports the use of text/xml. And, as he points out in the appendix and Mark Pilgrim does in his article, UAs (browsers to the rest of us) that support XHTML sent as application/xhtml+xml all support XHTML sent as text/xml too. As an added bonus, this means that TrackBack code can now be validly inserted into the file instead of hacked in inside comments.

Off to update my templates and CSS, and track down those nasty character entity references.

[Later: D’oh! First post in valid-XHTML-land and it gets screwed up by a macro expansion inside an attribute. Worked around in anticipation of a fix.]

[Even later: Following Ian’s comment, I’m back to the original application/xhtml+xml. My thoughts on text/xml allowing TrackBack inline actually still apply. And I’m still trying to figure out Pingback for Movable Type, based on Stuart Langridge’s code. Perhaps Stumbling would have been a better title.]

Baby steps

Mark Pilgrim has updated his site based on recommendations from Ian Hickson on building a perfect Web log. Following some of their lead, I’ve added the first bit of browser checking to my site using Apache’s mod_rewrite. The module has always scared me, but using what amounts to an identity rewrite I’ve managed to dynamically change the MIME type returned for my weblog pages. Here’s how it works.

RewriteEngine on

This line turns on the rewriting engine for the current directory and all subdirectories below it.

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[5-9].* [OR]
RewriteCond %{HTTP_USER_AGENT} ^Amaya/[5-9].*

These two lines define the conditions where the following rule will apply. They look at the HTTP_USER_AGENT variable (i.e. the User-Agent: field in the HTTP request) and check that it begins with Mozilla/ or Amaya/ followed by a major revision that is known or presumed to support the correct MIME type for XHTML files. (I’m working under the assumption that if it’s supported in an earlier version it will continue to be supported in a later one.)

RewriteRule ^(.*)\.html$ - [T=application/xhtml+xml]

Finally, I add the rule itself: any file that has the extension .html gets mapped to exactly the same name. By itself that’s useless and just wastes cycles on each request… except for the T= field that resets the MIME type, which was the original goal.

Easy peasy.

Right now, all of these lines are in a .htaccess file in the weblog directory. If/when I update the rest of the site to a version of XHTML (most of it has been, but I’m not confident enough to switch completely yet), these rules will migrate to my global httpd.conf.