Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between {R:1} and {C:1} on iis web.config file

Tags:

php

nginx

iis

azure

ON my job I was asked to migrate a php application running on iis/azure into running via nginx and fpm over a GNU+Linux machine.

Then on the process I encountered a file named web.config containing entries for example:

<action name="SomeName" stopProcessing="true">
   <match url=".*" ignoreCase="true" />
   <conditions>
      <add input="{URL}" pattern="^some_regex^">
   </conditions>
   <action type="Rewrite" url="index.php?someaction={C:1}">
</action>

Or

<action name="SomeName" stopProcessing="true">
   <match url=".*" ignoreCase="true" />
   <conditions>
      <add input="{URL}" pattern="^some_regex^">
   </conditions>
   <action type="Rewrite" url="index.php?someaction={R:1}">
</action>

So far I thought that an nginx mapping like that:

^some_regex^ index.php?someaction=$1;

Would do the job in both actions (somehow). But I still cannot understand the difference between {C:1} and {R:1} on regex maches I understand that in my nginx would be something like $1 (a subregex match) but what different to the web.config is {C:1} and {R:1} entries?

I am asking because I may need to change the nginx's subregex matches a bit regarding if the match is {C:1} or {R:1}.

like image 789
Dimitrios Desyllas Avatar asked Oct 05 '17 12:10

Dimitrios Desyllas


1 Answers

here is your answer

Back-references to condition patterns are identified by {C:N} where N is from 0 to 9. Back-references to rule patterns 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. For more detailed info you can have a look on: IIS URL Rewrite {R:N} clarification

Further info you can find on: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#using-back-references-in-rewrite-rules

like image 119
Dhaval Purohit Avatar answered Oct 05 '22 19:10

Dhaval Purohit