【问题标题】:Difference between {R:1} and {C:1} on iis web.config fileiis web.config 文件中 {R:1} 和 {C:1} 之间的区别
【发布时间】:2018-03-17 01:09:54
【问题描述】:

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

然后在进程中我遇到了一个名为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>

或者

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

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

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

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

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

【问题讨论】:

    标签: php azure iis nginx


    【解决方案1】:

    这是您的答案

    对条件模式的反向引用由 {C:N} 标识,其中 N 是从 0 到 9。对规则模式的反向引用由 {R:N} 标识,其中 N 是从 0 到 9。请注意,对于这两种类型的返回-references,{R:0}{C:0},将包含匹配的字符串。更多详细信息您可以查看:IIS URL Rewrite {R:N} clarification

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

    【讨论】:

    • 那么就我而言,规则是什么?据我所知,&lt;conditions&gt;&lt;/condtions&gt; 部分的情况可能不止一个条件,{C:1} 与此有关吗?你能举个例子说明{R:N}{C:N} 之间的区别很明显吗?
    • 我也必须找到。
    • 我在答案中添加了另一个链接,这将帮助您了解{R:N} 和` {C:N}` 之间的区别
    • 我认为第二个链接更具解释性。
    猜你喜欢
    • 2022-05-04
    • 2022-10-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2020-04-01
    • 2018-05-05
    • 1970-01-01
    • 2019-04-27
    相关资源
    最近更新 更多