且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS URL 重写 {R:N} 说明

更新时间:2023-02-24 11:21:56

根据文档:

当使用 ECMAScript 模式语法时,可以使用反向引用通过在模式的部分周围加上括号来创建必须捕获反向引用.

When an ECMAScript pattern syntax is used, a back-reference can be created by putting parenthesis around the part of the pattern that must capture the back-reference.

因此以文档中的示例为例:

So taking the example that follows in the documentation:

^(www.)(.*)$

并在条件中使用输入字符串www.foo.com,您将获得:

And using the input string www.foo.com in the conditions, you will have:

{C:0} - www.foo.com
{C:1} - www.
{C:2} - foo.com

为了简单起见:

  • {R:x} 用作规则模式的反向引用().
  • {C:x} 用作条件模式的反向引用(;</conditions>)
  • 0 引用包含整个输入字符串
  • 1 引用将包含与第一个括号 () 中的模式匹配的字符串的第一部分,2 引用第二个括号一,等等......直到参考号9
  • {R:x} is used as back reference from the rule pattern (<match url="...">).
  • {C:x} is used as back reference from the condition pattern (<conditions><add input="{HTTP_HOST}" pattern="..."></conditions>)
  • The 0 reference contains the whole input string
  • The 1 reference will contain the first part of the string matching the pattern in the first parenthesis (), the 2 reference the second one, etc...up to the reference number 9

注意:

当使用通配符"模式语法时,反向引用总是在模式中使用星号 (*) 时创建.不在?"时创建反向引用用于模式.

When "Wildcard" pattern syntax is used, the back-references are always created when an asterisk symbol (*) is used in the pattern. No back-references are created when "?" is used in the pattern.

http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Using_back-references_in_rewrite_rules