brothercake
05-10-2003, 10:16 PM
This isn't a question, I'm just posting info for reference.
A big problem with serving XHTML as application/xhtml+xml is that IE doesn't understand the mime-type, and tries to download the page instead of displaying it. What's needed is a way of changing the mime-type conditionally - get the browser to tell us what it accepts.
Here are two ways:
1 - using mod_rewrite in an Apache .htaccess file:
# serve .xhtml as xml - this could equally be .html
AddType application/xhtml+xml xhtml
# serve as tag soup if necessary
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)
RewriteCond %{REQUEST_FILENAME} .*\.xhtml
RewriteRule ^.*$ - "[T=text/html,L]"
2 - using PHP; this method is double-useful because you can also add the <?xml?> processing instruction if appropriate:
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
header("Content-type: application/xhtml+xml");
echo ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
}
else { header("Content-type: text/html"); }
?>
A big problem with serving XHTML as application/xhtml+xml is that IE doesn't understand the mime-type, and tries to download the page instead of displaying it. What's needed is a way of changing the mime-type conditionally - get the browser to tell us what it accepts.
Here are two ways:
1 - using mod_rewrite in an Apache .htaccess file:
# serve .xhtml as xml - this could equally be .html
AddType application/xhtml+xml xhtml
# serve as tag soup if necessary
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)
RewriteCond %{REQUEST_FILENAME} .*\.xhtml
RewriteRule ^.*$ - "[T=text/html,L]"
2 - using PHP; this method is double-useful because you can also add the <?xml?> processing instruction if appropriate:
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
header("Content-type: application/xhtml+xml");
echo ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
}
else { header("Content-type: text/html"); }
?>