The moment I changed the looks of this site, I also changed the version of the code used for these pages.

My site is now made up in XHTML version 1.1. I only forgot to change one thing.

I did change some elements to their new variants, and of course I included the right DTD. But my pages were still served to your browser with the text/html MIME type, while the specification tells me that I should serve my pages as application/xhtml+xml.

The specification is quite clear in this, but as usual the reality is more complicated. I could simple change the file extensions to .xhtml, which are automatically send with the right MIME type. But at this moment a lot of browsers (including IE6) are not able to handle this kind of documents.

So I need to distinguish browsers that can handle application/xhtml+xml from those that cannot handle it. Fortunately, most browsers send a list of MIME types they can handle each time they request a file from the server; so all I have to do is look at this list, and change the MIME type for modern browsers.

Therefore I added the following lines to my .htaccess file:

RewriteCond %{HTTP_ACCEPT} application/xhtml+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml+xml\s;\sq=0
RewriteCond %{REQUEST_URI} .html$
RewriteCond %{THE_REQUEST} HTTP/1.1
RewriteCond %{HTTP_HOST} !
RewriteRule .* - [T=application/xhtml+xml]

The first line looks whether the MIME type is in the accepted list of the browser.

The second lines looks whether it does not have q=0 (q stands for quality), which means that the browser does not want to use this MIME type.

The third line limits the requests to .html files only, since we do not want to change the MIME type for images, stylesheets and other files.

The fourth line limits the requests to HTTP version 1.1.

The fifth line excludes my photo pages, since I haven’t updated them to XHTML1.1 yet.

And the last line finally specifies the right MIME type for requests that satisfy all conditions above.

3 thoughts on “application/xhtml+xml”

  1. Google AdSense and XHTML1.1

    Visitors using older browsers like IE might have noticed that I recently started serving advertisements through Google. People using more modern browsers as Mozilla or Firebird might not have noticed this, since these advertisements are not visible for…

  2. So, if I understand this right, you serve your XHTML 1.1 as “application/xhtml+xml” if the browser claims to be able to handle that. Otherwise you serve _the same XHTML_ (still version 1.1) as “text/html”. Right?
    That is not the right thing to do. You need to serve out XHTML 1.0 (or even HTML 4.01) when you announce “text/html”. That means changing the Doctype declaration, and probably a lot of other things to in the code. The XHTML 1.0 code should conform to the Compatibility Guidelines of the XHTML 1.0 Recommendation.
    This is what I do at my site. I use PHP to check out the Accept header, and to convert the code (lots of regular expressions…). I also make an exception for Netscape 6. It claims to be able to handle “application/xhtml+xml”, but actually it can’t.
    It’s not all that easy to use XHTML 1.1. It’s still very much bleeding edge, or even beyond that.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.