IIS URL重写{R:N}的说明 [英] IIS URL Rewrite {R:N} clarification
问题描述
我无法理解{R:N}的目的.任何人都可以弄清楚何时使用
{R:0}
与{R:1}
I've not been able to understand the purpose of {R:N}. Could anyone please clarify when to use
{R:0}
vs. {R:1}
用法示例:
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
我看过使用{R:1}的ScottGu
I've seen ScottGu using {R:1}
Had a look at the IIS link below but could not quite digest the definition below:
条件模式的后向引用由{C:N}标识,其中N为0到9; N为0到9.规则模式的反向引用由{R:N}标识,其中N为0到9.请注意,对于两种类型的反向引用,{R:0}和{C:0}都将包含匹配的字符串
Back-references to condition patterns are identified by {C:N} where N is from 0 to 9; back-references to rule pattern are identified by {R:N} where N is from 0 to 9. Note that for both types of back-references, {R:0} and {C:0}, will contain the matched string
推荐答案
根据文档:
使用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}
用作规则模式(<match url="...">
)的后向引用. -
{C:x}
用作条件模式(<conditions><add input="{HTTP_HOST}" pattern="..."></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()
, the2
reference the second one, etc...up to the reference number9
注意:
使用通配符"模式语法时,始终使用反向引用 在模式中使用星号(*)时创建.不 向后引用是在?"时创建的用于模式.
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.
这篇关于IIS URL重写{R:N}的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!