Question

I tried to look for more info on back reference. But the ones i found aren't very clear. So I am really confused. I have this in a web.config

  <system.webServer>
<rewrite>
  <rules>
    <clear />

    <rule name="CTVNews Articles" stopProcessing="true">
      <match url="(.*?)CTVNews(/?)(.*)" />
      <action type="Redirect" url="http://www.ctvnews.ca{R:2}{R:3}" appendQueryString="true" redirectType="Permanent" />
    </rule>

so, I know that is the rule with regular expression.That is easy to understand, but what about url="http://www.ctvnews.ca/generic{R:2}{R:3}. Can someone please kindly explain what is R2 and R3? and why we have R2, R3, instead of R1 and R2?

All help is greatly appreciate it.

Was it helpful?

Solution

In the XML snippet you provided, the regular expression has three "capturing groups" - that is, use of parentheses ("(" and ")"). These "capture" whatever is inside them, and can then be referred to by number. There are numbered left-to-right, starting from 1.

Then in the <action> tag above, the {R:2} parts are referring to what the groups in the regular expression captured. There are three such groups, but the <action> is only using the second and third. The first one is being captured but is not being used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top