The Correlation Between XHTML and Mime-Type
To properly use XHTML one should send an application/xhtml+xml mime-type.
The language of the specifications says you SHOULD use application/xhtml+xml, but you MAY use application/xml or text/xml and you SHOULD NOT use text/html. This last one is important, since most people writing XHTML code don't respect this and send the UA "tag soup," hoping the UA's error handling procedure renders the site correctly. Read this document for more info.
I do this with a little PHP, which is below:
// This code is freely available with no warranty.
function printContentType() {
if (strpos($_SERVER['HTTP_ACCEPT'],"application/xhtml+xml")) {
header("Content-type: application/xhtml+xml\n");
}
elseif (strpos($_SERVER['HTTP_ACCEPT'],"application/xml")) {
header("Content-type: application/xml\n");
}
elseif (strpos($_SERVER['HTTP_ACCEPT'],"text/xml")) {
header("Content-type: text/xml\n");
else {
header("Content-type: text/html\n");
}
}
// Call this function before printing anything by using printContentType();
(fig. 1)
An alternate way to achieve this without the use of PHP is by using Apache's .htaccess mechanism:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)
RewriteCond %{REQUEST_FILENAME} .*\.xhtml
RewriteRule ^.*$ - "[T=text/html,L]"
// Or using Apache's .htaccess
There's another way you can use valid mime types with Apache by using content negotiation (mod_mime_magic) and map files.
Created: 23 Oct 03 - Modified: 28 May 06. Validate
© 2002-2008
Lisa Seelye.