我有一个非常简单的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脚本资源,例如 <script src="ScriptResource.axd?d=...." type="text/javascript" />
.
默认情况下,脚本资源是gzip压缩的,我希望保持这种方式 . 如果没有内容类型前置条件,URL重写器 RewriteModule
会抛出500.52错误 - “当HTTP响应的内容被编码时,不能应用出站重写规则("gzip") . ”
使用Fiddler我可以看到 Content-Type: text/html; charset=utf-8
正在响应头中发送,但UrlRwriter似乎无法匹配 .
为什么会这样?
1 回答
这是因为服务器变量
HTTP_ACCEPT_ENCODING
未添加到允许的服务器变量列表中 . 在那里添加(你可以谷歌如何在IIS中) .