I've not been able to understand the purpose of {R:N}. Could anyone please clarify when to use
{R:0}
vs. {R:1}
usage example:
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
I've seen ScottGu using {R:1}
Whereas, below has {R:0}
http://weblogs.asp.net/owscott/archive/2009/11/27/iis-url-rewrite-rewriting-non-www-to-www.aspx
Had a look at the IIS link below but could not quite digest the definition below:
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
Best Answer
As per the documentation:
So taking the example that follows in the documentation:
And using the input string
www.foo.com
in the conditions, you will have:To make it simple:
{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>
)0
reference contains the whole input string1
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
Note:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Using_back-references_in_rewrite_rules