简体   繁体   中英

ASP.net Web.Config Redirect Rules

I am having an issue with this redirect. I am trying to permanently redirect each state's installation location page to the new one. This is one example and it works fine.

<rule name="49 set wyoming/installation-locations 301 permanently moved" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_HOST}{REQUEST_URI}" pattern="wyoming/installation-locations" />
  </conditions>
  <action type="Redirect" url="/locations/wy/" redirectType="Permanent" />
</rule>

Now when I have to redirect the main installation-locations page (below) it works, but this new redirect rule overwrites the one above and the ones for every other state.

<rule name="locations redirect" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_HOST}{REQUEST_URI}" pattern="installation-locations" />
  </conditions>
  <action type="Redirect" url="/locations/" redirectType="Permanent" />
</rule>

Does anyone have any recommendations?

Try settings the pattern to accept nothing else before the installation-locations of the locations redirect rule.

<rule name="locations redirect" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_HOST}{REQUEST_URI}" pattern="^(installation-locations)$" />
  </conditions>
  <action type="Redirect" url="/locations/" redirectType="Permanent" />
</rule>

More info: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/testing-rewrite-rule-patterns

According to your description, the most easily way to solve it is modify the url rewrite rule order.

Since the installation-locations could also match the "wyoming/installation-locations" pattern, you will find the locations redirect rule is useless.

As far as I know, the url rewrite rule match is one by one. It will use the first rule, then second, third. If the rule is match the first one, it will not coutinue match second.

I suggest you could try to use below url rewrite rule, it will work well.

 <rule name="49 set wyoming/installation-locations 301 permanently moved" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_HOST}{REQUEST_URI}" pattern="wyoming/installation-locations" />
  </conditions>
  <action type="Redirect" url="/locations/wy/" redirectType="Permanent" />
</rule>
  <rule name="locations redirect" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_HOST}{REQUEST_URI}" pattern="installation-locations" />
  </conditions>
  <action type="Redirect" url="/locations/" redirectType="Permanent" />
</rule>

We solved this by placing server side script in the skin of the page.

if (DotNetNuke.Entities.Tabs.TabController.CurrentPage.TabName == "Installation Locations")
Response.Redirect("/locations");

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