【问题标题】:Converting IIS rewrite rule to Apache将 IIS 重写规则转换为 Apache
【发布时间】:2016-01-02 16:05:28
【问题描述】:

所以我在将 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/$1 [P]

【问题讨论】:

  • 您是在尝试代理此请求,还是只是重定向/重写到新的 url?
  • 代理。我想我已经弄清楚了。在下面回答。

标签: apache mod-rewrite iis url-rewriting proxy


【解决方案1】:

所以看起来我没有尊重原始规则中的原始 pod,该规则在请求中带有“/api”。下面的修改规则现在就像一个魅力(虽然我已经硬编码了路径的“/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/$1 [P]

【讨论】:

    猜你喜欢
    • 2014-10-29
    • 2011-04-25
    • 2012-07-12
    • 2014-07-03
    • 1970-01-01
    • 2014-06-30
    • 2016-08-09
    • 1970-01-01
    • 2013-10-14
    相关资源
    最近更新 更多