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}" />
我见过 ScottGu 使用 {R:1}
I've seen ScottGu using {R:1}
然而,下面有 {R:0}
Whereas, below has {R:0}
http://weblogs.asp.net/owscott/archive/2009/11/27/iis-url-rewrite-rewriting-non-www-to-www.aspx
查看了下面的 IIS 链接,但不能完全理解下面的定义:
Had a look at the IIS link below but could not quite digest the definition below:
对条件模式的反向引用由 {C:N} 标识,其中 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}
用作规则模式的反向引用(
).{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()
, 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屋!