[lug] Serving XHTML as text/html

Zan Lynx zlynx at acm.org
Mon Oct 30 18:10:59 MST 2006

On Mon, 2006-10-30 at 15:19 -0700, Matt Thompson wrote:
> I have an Apache question for the list that I'm sure is easy to do.
> Namely, my personal webpage is XHTML and is served as 
> application/xhtml+xml and for most modern browsers, that is fine.  Of 
> course, IE6 (dillo, lynx...) borks on that, but I never really cared nor 
> had the ability to do anything about that (the page below is served on 
> an external server).
> But, now I am setting up a web server that I have direct control over, 
> so I thought I could fix it.  Plus, the fact that IE7 doesn't do XHTML 
> either makes me think it's time.
> What I'd like to do is have a way to send my XHTML pages as text/html to 
> those browsers that can't do app/xhtml.  Most solutions I've seen use 
> the HTTP_ACCEPT header (cool), but are in PHP or CGI.  I'd rather not 
> rely on adding a ?php to each page or anything like that.
> So, I was wondering if there was an easy way to do it in httpd.conf. 
> I'm sure there is, and I've seen quite a few possibles on the interweb 
> using mod_rewrite or mod_negotiate.  But I'm not enough of an Apache 
> user to know if I'd be doing bad things using a config from a 2003 blog 
> post that was safe then, but double-plus-ungood now.  (Or if the modules 
> on those pages still exist...)

I use mod_negotiation and a typemap on my simple site:

I assume that it is still recommended since Apache 2.0 uses it for its
error messages and manuals.

DirectoryIndex index.var index.html
AddHandler type-map var
AddType application/xhtml+xml .xhtml

index.var looks like:
URI: index

URI: index.en.html
Content-Type: text/html
Content-Language: en

URI: index.en.xhtml
Content-Type: application/xhtml+xml
Content-Language: en

I believe the language stuff is just in there from the example I started

The order you list them in is very important for IE.  I believe IE just
has some sort of Accept: * header, so if you put XML first, IE takes it,
or rather, mod_negotiate gives it the first match.

My xhtml file is a symlink to the html file, but I think you might be
able to get away with using the same filename in the type-map.  Not sure

Another Apache 2.0 bit I use on my site that helps download speed a LOT
is this:
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml
application/xhtml+xml application/xml application/x-javascript

I've been playing with sending the client a XML of all the books in my
e-book library and using client-side XSLT to display and sort it.
Deflate/gzip shrinks those XML files by 14 times!  CPU usage isn't bad
for me, but it isn't a high volume site.
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20061030/252aa69f/attachment.pgp>

More information about the LUG mailing list