将 IIS 重写规则转换为 Apache

Converting IIS rewrite rule to Apache

所以我在将 IIS 中的这个重写规则转换为 Apache 时遇到了问题。在 IIS 中运行良好,但在 Apache 中运行不佳。

原来的 IIS 重写规则:

<rule
 enabled="true"
 stopProcessing="true"
 name="Route API calls to test server”>
 <match url="(api/.*)" />
 <action type="Rewrite" url="http://api.testdomain.com/{R:1}" />
</rule>

我正在尝试的 Apache 规则:

RewriteEngine on
RewriteRule ^api/(.*)$ http://api.testdomain.com/ [P]

所以看起来我没有遵守带有请求的“/api”的原始规则中的原始 pod。下面修改后的规则现在就像一个魅力(虽然我已经硬编码了路径的'/api'部分,但结果相同)。

原来的 IIS 重写规则:

    <rule
    enabled="true"
    stopProcessing="true"
    name="Route API calls to test server”>
    <match url="(api/.*)" />
    <action type="Rewrite" url="http://api.testdomain.com/{R:1}" />
    </rule>

Apache 规则

    RewriteEngine on
    RewriteRule ^/api/(.*)$ http://api.testdomain.com/api/ [P]