【问题标题】:IIS UrlRewriter Outbound rules ignored if PreCondition is set如果设置了 PreCondition,则忽略 IIS UrlRewriter 出站规则
【发布时间】:2012-01-26 21:27:00
【问题描述】:

我有一个非常简单的 OutBound UrlRewriter 规则,它重写它在 http 响应流的正文中找到的 url:

<rewrite>
  <outboundRules>
    <rule name="Scripted" 
          preCondition="IsHtml" 
          patternSyntax="ECMAScript" 
          stopProcessing="false">
      <match filterByTags="None" pattern="http://someurl.com" />
      <action type="Rewrite" value="http://anotherurl.com" />
    </rule>

    <preConditions>
      <preCondition name="IsHtml" patternSyntax="Wildcard">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>

  </outboundRules>
</rewrite>

问题是只要我打开preCondition 就不会发生重写。

我需要能够使用前置条件,因为该页面是 ASP.NET 页面并使用 ASP.NET 脚本资源,例如&lt;script src="ScriptResource.axd?d=...." type="text/javascript" /&gt;

默认情况下,脚本资源是 gzip 压缩的,我想保持这种方式。如果没有内容类型前提条件,URL 重写器RewriteModule 会抛出 500.52 错误 - “当 HTTP 响应的内容被编码(“gzip”)时,无法应用出站重写规则。

使用 Fiddler 我可以看到 Content-Type: text/html; charset=utf-8 正在响应标头中发送,但 UrlRwriter 似乎无法匹配。

为什么会这样?

【问题讨论】:

    标签: iis-7 url-rewriting urlrewriter


    【解决方案1】:

    这是因为服务器变量HTTP_ACCEPT_ENCODING 未添加到允许的服务器变量列表中。在那里添加它(你可以谷歌如何在 IIS 中)。

    【讨论】:

    猜你喜欢
    • 2012-03-30
    • 1970-01-01
    • 2018-11-13
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多