go to the content followme

Wikier.org

  1. 11 Jul 2008

    Serving XHTML to IE

    IE doesn’t support XML, it’s an old problem of this browser. So you can’t serve any mime type of XML (such XHTML), because it doesn’t know how to handler it (it offers it to download). But as it still is the browser with the biggest quote of users (I can’t understand why…), web developers have to take care of the behavior of this browser. That’s the reason because everybody is still serving XHTML (application/xhtml+xml) as simple HTML (text/html); it seems that works, but really it’s not too correct.

    If you are generating the document, you can patch this thing in your application (as Diego told for Textpattern). But if you have only static documents, that trick is not so obvious. This morning, with the invaluable help of Tejo, we founded the way to do it transparently just using mod_rewrite of Apache:

    AddType  application/xhtml+xml .html
    RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml
    RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)
    RewriteCond %{REQUEST_FILENAME} .*\.html
    RewriteRule ^.*$ - "[T=text/html,L]"

    So if an agent requests application/xhtml+xml, it’ll serve it in the response. But if any lost agent (such as IE) requests just text/html, that will be the mime type served. It’s not so obvious, so this post is to remember it to me in the future.