iis web.config 文件中 {R:1} 和 {C:1} 的区别

Dim*_*las 7 php iis nginx azure

在我的工作中,我被要求将在 iis/azure 上运行的 php 应用程序迁移到在 GNU+Linux 机器上通过 nginx 和 fpm 运行。

然后在这个过程中,我遇到了一个名为web.config包含条目的文件,例如:

<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>
Run Code Online (Sandbox Code Playgroud)

或者

<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>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我认为这样的 nginx 映射:

^some_regex^ index.php?someaction=$1;
Run Code Online (Sandbox Code Playgroud)

会在两个动作中完成工作(以某种方式)。但是我仍然无法理解正则表达式机器上 {C:1} 和 {R:1} 之间的区别我知道在我的 nginx 中类似于 $1(一个子正则表达式匹配)但是与 web.config 不同的是 {C: 1} 和 {R:1} 条目?

我问是因为我可能需要稍微更改 nginx 的子正则表达式匹配项是 {C:1} 还是 {R:1}。

Dha*_*hit 8

这是你的答案

条件模式的反向引用由{C:N}N 为从 0 到 9 的位置标识。规则模式的反向引用由{R:N}N 是从 0 到 9 的位置标识。请注意,对于两种类型的反向引用,{R:0}{C:0}将包含匹配的细绳。有关更多详细信息,您可以查看:IIS URL Rewrite {R:N} 说明

您可以在以下位置找到更多信息:https : //docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#using-back-references-in-rewrite -规则

  • 我也必须找到。 (2认同)