有没有办法确定IIS'出站重写规则仅在请求的URL与模式匹配时才适用?我怀疑这是不可能的,因为请求网址在回复中不可见,但我想我会希望它是可能的。
这是我目前的出境规则:
<rewrite>
<outboundRules>
<rule name="Change Absolute Paths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://blog.mycompany.com/blog(.*)$" />
<action type="Rewrite" value="https://www.mycompany.com/blog{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
如果我可以在那里添加一个条件,那么只有在请求URL与模式匹配时才适用出站规则,这将是很好的。
答案 0 :(得分:2)
事实证明这很容易。您只需在{REQUEST_URI}
上添加条件。
<rewrite>
<outboundRules>
<rule name="Change Absolute Paths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://blog.mycompany.com/blog(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/foobar" />
</conditions>
<action type="Rewrite" value="https://www.mycompany.com/blog{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>