Recipe 12.5 Setting the Content-Type According to Browser Capability


You want to set Content-Type headers differently for different browsers, which may render the content incorrectly otherwise.


Check the Accept headers with RewriteCond and then set the Contend-Type header with a T flag:

RewriteCond "%{HTTP_ACCEPT}" "application/xhtml\+xml" RewriteCond "%{HTTP_ACCEPT}" "!application/xhtml\+xml\s*;\s*q=0+(?:\.0*[^0-9])" RewriteRule . - [T=application/xhtml+xml;charset=iso-8859-1]


Different browsers tend to deal with content differently and sometimes need a nudge in the right direction. In this example, for browsers that specify (using the HTTP_ACCEPT header) that they prefer XHTML content, we want to send a Content-Type header specifying that the content we are sending fulfills that requirement.

The T (Type) flag sets the Content-Type for the response.

See Also


Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: