The Tridecadal Korean (astralblue) wrote,
The Tridecadal Korean

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.

Tags: apache, ie, internet explorer, xhtml

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.