Log in


Apache Tip: IE+“application/xhtml+xml”=T_T

If your site has a bunch of .xhtml files which choke IE 'cause Apache serves 'em under application/xhtml+xml:

RewriteCond %{REQUEST_URI} !\.xhtml$
RewriteRule ^ - [skip=2]

RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteRule ^ - [skip=1]

RewriteRule ^ - [type=text/html]

Basically that means: If the filename extension is .xhtml and the HTTP Accept: header either doesn't have application/xhtml+xml defined or has it defined but with quality of zero (meaning: I refuse the type), override its MIME type and return it as text/html.  This uses the fact that Mozilla/Firefox explicitly includes application/xhtml+xml in the Accept: header of each and every HTTP request while IE does not.

Note: If you have .xhtml defined in DirectoryIndex and want the above snippet to work for the directory URLs as well, it must be defined in the main httpd.conf; defining it in .htaccess does not work for an obscure reason that involves Apache's internal subquery processing.


The only problem then is the fact that you lose some benefits of XHTML when serving it as text/html

But you knew that already!
Not like IE would take advantage of those benefits anyways, even if it didn't narf on application/xhtml+xml :P

IINM, IE enters the XHTML standard compliance mode as long as the “<?xml>” prolog is not there and the correct XHTML DOCTYPE is provided.  According to IEBlog, the XML prolog restriction will be lifted in IE7 (so authors can use the prolog to specify an alternative encoding, for example) as well.

Yeah, IE is weird like that. :D

FYI, here's the IEBlog article ] that declared IE7 would not support application/xhtml+xml along with the reason why it wouldn't, which I personally think is perfectly valid.

As long as they re-do the parser in the future, I'll refrain my comments for now.
Not wanting to do a buggy implementation is a good thing, time permitting, but I hopehopehopehopehope it's done sooner rather than later.