我有一个非常简单的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响应的内容被编码时,”“” “ p>
使用Fiddler我可以看到响应标头中发送了Content-Type: text/html; charset=utf-8
,但UrlRwriter似乎无法与此匹配。
为什么会这样?
答案 0 :(得分:3)
这是因为服务器变量HTTP_ACCEPT_ENCODING
未添加到允许的服务器变量列表中。在那里添加(你可以在IIS中谷歌如何)。