【问题标题】:IIS URL rewrite rule using conditions使用条件的 IIS URL 重写规则
【发布时间】:2015-04-26 14:50:34
【问题描述】:

我在 web.config 文件中配置了以下 URL 重写规则:

<rule name="Test Rule" stopProcessing="true">
  <match url="^$" />
  <conditions>
    <add input="{QUERY_STRING}" pattern="^(item=1|all|none|first).*$" />
  </conditions>
  <action type="Rewrite" url="/newsite/test.asp?{C:0}" />
</rule>     

以下来源网址符合预期。

http://domainname?item=1&param1=x%param2=y

但是,重写后的 url 在其查询字符串中包含 param1 和 param2。 {C:0} 不应该只转换为正则表达式组中匹配的内容,即 (item=1|all|none|first) 而不是它之后的任何内容吗?

【问题讨论】:

  • 尝试改用{C:1}

标签: asp.net regex iis url-rewriting web-config


【解决方案1】:

重写捕获( ) 之后的所有内容的原因是因为{C:0} 捕获了整场比赛,而不仅仅是组。由于您只想捕获 ( )(即捕获组 1)中的内容,因此您可以使用:

{C:1}

另一个例子可能是:

^(item=1|all|none|first)/(abc).*$

例如仅捕获abc(捕获组2):

{C:2}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 2014-05-01
    • 2011-04-21
    • 1970-01-01
    • 2014-01-05
    相关资源
    最近更新 更多