IIS URL 重写删除部分路径

IIS URL Rewrite remove part of path

在研究 url 重写和审阅许多帖子后,我仍然对为什么我的 url 重写不起作用感到困惑。我正在尝试从路径中删除 /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>

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

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