IE6 gzip bug和IIS7 URL重写模块

时间:2009-11-19 21:52:36

标签: iis-7 url-rewriting

我们遇到了令人讨厌的偶发IE6错误,在js和css文件上启用了gzip压缩会使事情变得糟糕(例如,请参阅Can i gzip-compress all my html content(pages))。

因此,似乎最好的解决方法是使用IIS7 / 7.5中的URL重写模块来检查来自< IE6并按照http://sebduggan.com/posts/ie6-gzip-bug-solved-using-isapi-rewrite对其进行解压缩。

  1. 我想使用IIS7 Url重写模块
  2. 只有IIS7 Url Rewrite Module 2.0 RC支持重写标题
  3. 但以下结果导致受影响资源出现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的服务器变量中放入什么?我已经确认这是问题行(因为其他所有内容都已被隔离并按要求运行)。我已经尝试了所有我能想到的东西,我开始认为只是不支持设置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重写模块错误。”

1 个答案:

答案 0 :(得分:3)

嗯,事实证明,出于安全原因,您需要在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

编辑:添加了官方文档链接。

编辑:添加了博客文章摘要的链接。

相关问题