【问题标题】:Scope IIS Rewrite Outbound Rule by request URL按请求 URL 范围 IIS 重写出站规则
【发布时间】:2016-03-16 05:03:37
【问题描述】:

有没有办法将 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 匹配模式时,那就太好了。

【问题讨论】:

    标签: iis rewrite outbound


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 2014-10-27
      • 2014-05-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多