Home > Back-end >  How to do 1 URL re-write rule for multiple ids?
How to do 1 URL re-write rule for multiple ids?

Time:05-17

I have these URLs:

https://www.example.com/amp/articles/10/title

https://www.example.com/amp/videos/11/title

I need to redirect only specific ids to non amp as follows:

https://www.example.com/articles/10/title

https://www.example.com/videos/11/title

Here's what I tried but there's no URL redirection, nothing occurs:

    <rule name="redirect_to_non_amp_for_specific_ids" stopProcessing="true">
      <match url="^amp/(articles|videos)/(10|11)/([^/] )/?$"/>
          <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}/{R:3}"/>
    </rule>

Note I need to avoid multiple url-rewrite rules.

CodePudding user response:

My rule is correct. I figured out I had to place it before other article rules, for priority, for the rule to take effect.

From microsoft: The rules are evaluated in the same order in which they are specified.

Reference: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

  • Related