IE6 gzip bug and IIS7 URL Rewrite Module
We're running into the nasty sporadic IE6 bug where gzip compression enabled on js and css files makes things go bad (see Can i gzip-compress all my html content(pages) for example).
Therefore, what seems to be the best way to deal with this would be to use the URL Rewrite Module in IIS7/7.5 to check for requests from < IE6 and serve them uncompressed as per http://sebduggan.com/posts/ie6-gzip-bug-solved-using-isapi-rewrite.
- I want to use the IIS7 Url Rewrite Module
- Only the IIS7 Url Rewrite Module 2.0 RC supports rewriting headers
But the following results in a 500 error for the affected resources:
<?开发者_如何转开发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>
What to put in the Server Variable for Accept-Encoding? I've verified that this is the problem line (as everything else has been isolated and operates as required). I've tried everything I can think of and I'm beginning to think that there just isn't support for setting the Accept-Encoding header.
I've tried:
<set name="HTTP_ACCEPT_ENCODING" value=" " />
<set name="HTTP_ACCEPT_ENCODING" value=".*" />
<set name="HTTP_ACCEPT_ENCODING" value="0" />
Specifically, it results in a "HTTP/1.1 500 URL Rewrite Module Error."
Well, it turns out that for security reasons you need to explicitly allow whatever server variables you wish to modify in the applicationHost.config (see http://learn.iis.net/page.aspx/665/url-rewrite-module-20-configuration-reference#Allowed_Server_Variables_List).
Therefore, the following does the trick in the 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>
As long as the applicationHost.config has:
<location path="www.site.com">
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_ACCEPT_ENCODING" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
See http://www.andornot.com/about/developerblog/2009/11/ie6-gzip-bug-solved-using-iis7s-url.aspx for a blog post detailing everything.
EDIT: Added official documentation link.
EDIT: Added link to blog post summarizing.
精彩评论