简体   繁体   English

IIS URL重写删除部分路径

[英]IIS URL Rewrite remove part of path

After researching url rewrite and reviewing many posts, I'm still stumped as to why my url rewrite is not working. 在研究了网址重写并查看了许多帖子之后,我仍然对为什么我的网址重写无法正常工作感到困惑。 I am attempting to remove /carrot/ from the path. 我正在尝试从路径中删除/carrot/

Ex: https://my.server.com/carrot/mobile/path 例如: https://my.server.com/carrot/mobile/pathhttps://my.server.com/carrot/mobile/path

should become: https://my.server.com/mobile/path 应该成为: https://my.server.com/mobile/path : https://my.server.com/mobile/path

My URL rewrite rule is pretty simple and looks as follows: 我的URL重写规则非常简单,如下所示:

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

All help is appreciated. 感谢所有帮助。

Edit Below you can find all rules in use in case this is an issue where various rules are clashing: 在下面编辑,您可以找到所有正在使用的规则,以防万一这是各种规则冲突的问题:

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

The solution to my issue was to use Redirect instead of Rewrite as follows: 解决我的问题的方法是使用Redirect而不是Rewrite ,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM