2009-11-19 46 views
0

我們遇到了令人討厭的零星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對其進行解壓縮。

  1. 我想用IIS7 URL重寫模塊
  2. 只有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重寫模塊錯誤」。

回答

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詳細說明一切。

編輯:添加官方文檔鏈接。

編輯:添加鏈接到博客文章總結。