首页 > 解决方案 > IIS URL Rewrite 删除部分路径

问题描述

在研究了 url rewrite 并查看了许多帖子之后,我仍然对为什么我的 url rewrite 不起作用感到困惑。我正在尝试/carrot/从路径中删除。

前任:https://my.server.com/carrot/mobile/path

应该变成:https://my.server.com/mobile/path

我的 URL 重写规则非常简单,如下所示:

    <rule name="RemoveCarrotFromPath">
      <match url=".*carrot(.*)" />
      <action type="Rewrite" url="{R:1}" />
    </rule>

感谢所有帮助。

编辑您可以在下面找到所有正在使用的规则,以防这是各种规则发生冲突的问题:

<rewrite>
  <rules>
    <rule name="redirectPayment" stopProcessing="true">
      <match url="/payment" />
      <action type="Redirect" url="https://my.app.com/carrot/Payment" />
    </rule>
    <rule name="redirectMembership" stopProcessing="true">
      <match url="/membership" />
      <action type="Redirect" url="https://my.app.com/carrot/Membership" />
    </rule>
    <rule name="RemoveCarrotFromPath">
      <match url=".*carrot(.*)" />
      <action type="Rewrite" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

标签: iisurl-rewritingurl-rewrite-module

解决方案


我的问题的解决方案是使用Redirect而不是Rewrite如下:

<rule name="RemoveCarrotFromPath">
  <match url=".*carrot(.*)" />
  <action type="Redirect" url="{R:1}" />
</rule> 

推荐阅读