under the subheading "mod_rewrite". The descriptive text is in
German, but the recipe itself should be clear enough.
As the author says, there is one little problem with this in the form
offered: if some client were to try to explicitly refuse the xhtml
format by sending application/xml+xhtml;q=0 then the code would
misinterpret it as a positive request rather than as a refusal; I
guess a bit of work with regular expressions could correct that.
Also if a branch of the filetree contained documents in several
different character codings, it would need a bit of work with the
Nevertheless, it has the benefit of needing only one static copy of
the source and not serving out the same content under different URLs,
as e.g symlinking the same source as .html and .xhtml versions would
The result (AFAICS) gets sent out with an appropriate 'Vary: accept'
header, and enough freshness validator data to be eligible for
cacheing (in proxy servers etc.), which is nice.
Sure, some would say this is based on a too simplistic underlying
approach - they would prefer to create a genuine XML-based source, and
deliver it, when necessary as HTML, by means of a transform process.
I'm just saying that if the simpler approach _is_ found acceptable,
then this technique seems a nifty way of applying it. Kudos to the
author, Christoph Schneegans (nice pages, too).
all the best
> Recently there was some discussion on the relevant de.* group, in
> which a useful mod_rewrite recipe came up for delivering the same
> source document as HTML or XHTML depending on the client's Accept
> header. It seems to me that this bit of ingenuity deserves a wider
> audience. The recipe is near the end of this page
Those who want to do the trick and aren't permitted to enable
mod_rewrite but can use .var maps might be interested in this script I
posted in a Mozilla-related NG in November:
@files = `ls -1`;
$stem = $1;
open(OUT, "> $stem.var")
or die ("Can't open $stem.var for output, $!\n");
print OUT "URI: $stem\n\n";
print OUT "URI: $stem.xml\n";
print OUT "Content-type: text/xml;q=0.99\n\n";
print OUT "URI: $stem.html\n";
print OUT "Content-type: text/html;q=1\n";