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} !photos.braintags.com
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.