IIS URL重写删除路径的一部分



在研究URL重写并审查了许多帖子后,我仍然对为什么我的URL重写不起作用感到难过。我试图从路径上删除/carrot/

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

最新更新