exo : blah


Thu, 01 May 2003

Some redirect sauce required

When I wrote yesterday about content negotiation I knew there was one small fly in the ointment: clients that didn't send an Accept header didn't get the file I wanted. If there's no Accept header then Apache falls back to the less useful trick of selecting the smallest of the matching files. This meant that for this weblog the RSS feed would be selected over the html version. This seemed to me to not be the expected result.

In order to fix this I first looked at type maps. These are files that allow you to tell Apache what values to use for the matching files, as well as telling it what the matching files are for a URI. I had two problems with them though: you have to provide a type map file for each URI; I couldn't get them to work. The second was the real clincher.

That being a failure I did what every seasoned Apache user does at times like these. I used mod_rewrite. A quick wander through the mod_rewrite documentation and you get the following rewrite rules.

    RewriteCond %{HTTP_ACCEPT} !.+
    RewriteRule (^/.*/[^/\.]+$)  http://exo.org.uk$1.shtml [R,L]

posted at: 05:59 #

all the usual copyright stuff... [ copyright struan donald 2002 - present ], plus license