IIS URL Rewrite {R:N} clarification

后端 未结 1 1402
盖世英雄少女心
盖世英雄少女心 2020-11-28 22:57

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:

相关标签:
1条回答
  • 2020-11-28 23:04

    As per the documentation:

    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\.)(.*)$
    

    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
    

    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>)
    • 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

    Note:

    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

    0 讨论(0)
提交回复
热议问题