简体   繁体   中英

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.

Ex: https://my.server.com/carrot/mobile/path

should become: https://my.server.com/mobile/path

My URL rewrite rule is pretty simple and looks as follows:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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