Apache Rewrite 覆盖 Mime 和代理请求?
我正在尝试实现一些 Apache 重写规则,以便为 Internet Explorer 中的 XHTML 正确设置 MIME 类型。我在很多地方都发现了这些重写规则,它们似乎对大多数人都有效:
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteRule .* - [T=text/html]
但是,我的站点已经使用带有 [P] 标志的重写规则来将请求代理到本地 Tomcat 实例。无论我做什么,上述规则似乎都会被 Tomcat 返回的 mime 类型覆盖。 Apache 文档对于 [P] 标志是这样说的:
该标志强制替换部分 作为代理在内部发送 请求并立即(重写 处理在此停止)
...所以我不能将 mime 规则放在代理规则之后。如果我将它们放在代理规则之前,则 mime 类型将被代理覆盖。
如果我使用代理规则,有什么方法可以设置 IE 的 mime 类型吗?或者是我在 Tomcat 中更改 mime 类型的唯一选择(不幸的是,需要更改代码)。
谢谢, 杰夫
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否有效,你可以尝试一下。应用两条规则,一条适用于 IE,另一条适用于非 IE。
没有浏览器检测的第二条规则
I'm not sure if this will work, you can try it. Apply two rules, one for IE and one for non IE.
Second rule without Browser detection