IE6 gzip错误和IIS7 URL重写模块
我们遇到了令人讨厌的零星IE6错误,其中在js和css文件上启用了gzip压缩会使事情变糟(例如参见Can i gzip-compress all my html content(pages))。IE6 gzip错误和IIS7 URL重写模块
因此,处理这个问题似乎是最好的方法,那就是使用IIS7/7.5中的URL重写模块来检查来自< IE6的请求,并根据http://sebduggan.com/posts/ie6-gzip-bug-solved-using-isapi-rewrite对其进行解压缩。
- 我想用IIS7 URL重写模块
- 只有IIS7 URL重写模块2.0 RC支持重写头
但以下结果在500错误受影响的资源:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="IE56 Do not gzip js and css" stopProcessing="true">
<match url="\.(css|js)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="MSIE\ [56]" />
</conditions>
<action type="None" />
<serverVariables>
<set name="Accept-Encoding" value=".*" /> <!-- This is the problem line -->
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
要放什么东西在服务器变量接受编码?我已经证实,这是问题线(因为所有其他东西都被隔离并按要求运行)。我尝试了所有我能想到的,我开始认为只是不支持设置Accept-Encoding标头。
我试着:
<set name="HTTP_ACCEPT_ENCODING" value=" " />
<set name="HTTP_ACCEPT_ENCODING" value=".*" />
<set name="HTTP_ACCEPT_ENCODING" value="0" />
具体地,它导致 “HTTP/1.1 500 URL重写模块错误”。
事实证明,出于安全原因,您需要明确地允许您希望在applicationHost.config中修改任何服务器变量(请参阅http://learn.iis.net/page.aspx/665/url-rewrite-module-20-configuration-reference#Allowed_Server_Variables_List)。
因此,下列情况在Web.config的伎俩:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="IE56 Do not gzip js and css" stopProcessing="false">
<match url="\.(css|js)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="MSIE\ [56]" />
</conditions>
<action type="None" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="0" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
只要具有的applicationHost.config:
<location path="www.site.com">
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_ACCEPT_ENCODING" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
的博客文章见http://www.andornot.com/about/developerblog/2009/11/ie6-gzip-bug-solved-using-iis7s-url.aspx详细说明一切。
编辑:添加官方文档链接。
编辑:添加链接到博客文章总结。