Search code examples
apacheinternet-explorerxhtmlmod-rewritemod-proxy

Apache Rewrite Override Mime and Proxy Request?


I am trying to implement some Apache rewrite rules to set the MIME type (in)correctly for XHTML in Internet Explorer. I have found these rewrite rules in many place, and they seem to work for most people:

  RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
  RewriteRule .* - [T=text/html]

However, my site is already using Rewrite rules with the [P] flag to proxy requests to a local Tomcat instance. No matter what I do, the above rules seem to be overridden by the mime type returned from Tomcat. The Apache docs say for the [P] flag:

This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here)

...so I can't put the mime rules after my proxy rules. If I put them before my proxy rules, the mime type is overridden by the proxy.

Is there any way to set the mime type for IE if I am using the proxy rules? Or is my only option to change the mime type in Tomcat (requiring a code change, unfortunately).

Thanks, Jeff


Solution

  • I'm not sure if this will work, you can try it. Apply two rules, one for IE and one for non IE.

    RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
    RewriteRule ^(.*)$ http://localhost-tomcat:8080/$1 [T=text/html,P,L]
    

    Second rule without Browser detection

    RewriteRule ^(.*)$ http://localhost-tomcat:8080/$1 [P,L]