范围 IIS 按请求重写出站规则 URL

Scope IIS Rewrite Outbound Rule by request URL

是否有任何方法可以将 IIS 的出站重写规则范围限定为仅在请求的 URL 匹配模式时应用?我怀疑这是不可能的,因为请求 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 匹配某个模式时才适用,那就太好了。

事实证明这很容易。您只需要在 {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>