Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created February 8, 2012 15:31
Show Gist options
  • Save GaryJones/1770484 to your computer and use it in GitHub Desktop.
Save GaryJones/1770484 to your computer and use it in GitHub Desktop.
.htaccess conditional application/xhtml+xml serving solutions
# Contains a list of potential solutions to amend and investigate later.
# http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule .* - [T=application/xhtml+xml]
# http://www.howtocreate.co.uk/wrongWithIE/?chapter=XHTML
AddType text/html .xhtml
...
RewriteEngine on
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml;\s*q=0(\.0)?\s*(,|$)
RewriteRule \.xhtml$ - [T=application/xhtml+xml]
# http://intertwingly.net/code/mombo/htaccess
# RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
# RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0\.?0*(\s|,|$)
# RewriteCond %{REQUEST_URI} ^([^.]*|.*\.html)$
# RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
# RewriteCond %{HTTP_ACCEPT} ^$
# RewriteCond %{REQUEST_URI} ^([^.]*|.*\.html)$
# RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
# RewriteCond %{HTTP_ACCEPT} !image/gif
# RewriteCond %{HTTP_ACCEPT} text/html\s*;\s*q=0\.?0*(\s|,|$) [OR]
# RewriteCond %{HTTP_ACCEPT} !text/html
# RewriteCond %{HTTP_ACCEPT} (application|\*)/(xhtml\+xml|\*)
# RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0\.?0*(\s|,|$)
# RewriteCond %{REQUEST_URI} ^([^.]*|.*\.html)$
# RewriteRule .* - [T=application/xhtml+xml;charset=utf-8]
#
# <Files comments.html>
# AddType application/xhtml+xml .html
# </Files>
# start with the assumption that everything is xhtml
AddType application/xhtml+xml html
RewriteRule ^([^.]*|.*\.html\d?)$ - [T=application/xhtml+xml;charset=utf-8]
# respect requests to not send xhtml
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml\s*;\s*q=0\.?0*(\s|,|$)
RewriteRule ^([^.]*|.*\.html\d?)$ - [T=text/html;charset=utf-8]
# standards based backwards compatibility - for tools like Lynx
RewriteCond %{HTTP_ACCEPT} text/html
RewriteCond %{HTTP_ACCEPT} !text/html\s*;\s*q=0\.?0*(\s|,|$)
RewriteCond %{HTTP_ACCEPT} !(application|\*)/(xhtml\+xml|\*)
RewriteCond %{HTTP_USER_AGENT} !chromeframe
RewriteRule ^([^.]*|.*\.html\d?)$ - [T=text/html;charset=utf-8]
# MSIE accomodation: simple click
RewriteCond %{HTTP_ACCEPT} image/gif
RewriteCond %{HTTP_ACCEPT} !html
RewriteCond %{HTTP_USER_AGENT} !chromeframe
RewriteRule ^([^.]*|.*\.html\d?)$ - [T=text/html;charset=utf-8]
# MSIE accomodation: open in new tab/window
RewriteCond %{HTTP_ACCEPT} ^\*/\*$
RewriteCond %{HTTP_USER_AGENT} MSIE\s[5678]
RewriteCond %{HTTP_USER_AGENT} !chromeframe
RewriteRule ^([^.]*|.*\.html\d?)$ - [T=text/html;charset=utf-8]
# Enable Google Chrome Frame
BrowserMatch chromeframe gcf
Header append X-UA-Compatible "chrome=1" env=gcf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment