代码之家  ›  专栏  ›  技术社区  ›  Ted

IE6 gzip错误和IIS7 URL重写模块

  •  0
  • Ted  · 技术社区  · 16 年前

    我们遇到了令人讨厌的零星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重写模块2.0 RC支持重写标头

    <?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>
    

    在接受编码的服务器变量中放入什么?我已经验证了这是问题线(因为其他一切都已隔离并按要求运行)。我已经尝试了我所能想到的一切,我开始认为不支持设置接受编码头。

    我试过:

    <set name="HTTP_ACCEPT_ENCODING" value=" " />
    <set name="HTTP_ACCEPT_ENCODING" value=".*" />
    <set name="HTTP_ACCEPT_ENCODING" value="0" />
    

    1 回复  |  直到 8 年前
        1
  •  3
  •   Ted    16 年前

    事实证明,出于安全原因,您需要在applicationHost.config中显式允许您希望修改的任何服务器变量(请参阅 http://learn.iis.net/page.aspx/665/url-rewrite-module-20-configuration-reference#Allowed_Server_Variables_List ).

    <?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>
    

    <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 一篇详细介绍一切的博客文章。

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