【问题标题】:Capture part of URL to use in Outbound rule for rewrite module in IIS捕获部分 URL 以在 IIS 中重写模块的出站规则中使用
【发布时间】:2015-06-09 22:58:03
【问题描述】:

有没有办法在出站规则中捕获部分 url 以用作重写的值?

现在,我正在使用先决条件,其中我有一个针对 {REQUEST_URI} 的模式的输入。我想在使用此前提条件的出站规则中使用请求 URI 中的捕获组。我试过 {C:1} 但没有用。

前提条件:

<preCondition name="Html Response" logicalGrouping="MatchAll">
    <add input="{REQUEST_URI}" pattern="myapp(.*)" />
    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^(text/html)" />
</preCondition>

出站规则:

<rule name="ResponseRewriteRelative" preCondition="Html Response" stopProcessing="true">
    <match filterByTags="A, Link" pattern="^/(.*)" />
    <action type="Rewrite" value="{C:1}/{R:1}" />
</rule>

其中 {C:1} 将是前置条件“myapp(.*)”中的捕获组

所以,它会从 http://myapp40.com 将响应中的链接重写为类似于 40/原文相对链接

谢谢!

【问题讨论】:

  • 您能否编辑您的问题并包括一个重写应该如何工作的示例?

标签: iis url-rewriting url-rewrite-module outbound preconditions


【解决方案1】:

我刚刚发现您可以向出站规则本身添加条件。只是在这里回答,以防有任何其他无知的人在重写规则中苦苦挣扎:)

规则看起来像:

<rule name="ResponseRewriteRelative" preCondition="Html Response" stopProcessing="true">
    <match filterByTags="A, Link" pattern="^/(.*)" />
    <action type="Rewrite" value="{C:1}/{R:1}" />
    <conditions>
        <add input="{REQUEST_URI}" pattern="myapp(.*)" />
    </conditions>
</rule>

【讨论】:

猜你喜欢
  • 2019-08-22
  • 2012-11-05
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 2012-03-11
  • 1970-01-01
  • 2014-10-27
相关资源
最近更新 更多