iisurl-rewriting

IIS URL Rewrite: Match URL with and without Slash


I want to redirect specific URLs permanently to other domains.

<rule name="URL Test" enabled="true" stopProcessing="true">
              <match url="^en/career/jobs$" />
              <conditions logicalGrouping="MatchAny">                   
                   
              </conditions>
              <action type="Redirect" url="https://www.example.com/newjobs" appendQueryString="false" redirectType="Permanent" />
            </rule>

It works when I use https://source.com/en/career/jobs but when I add a slash in the end (https://source.com/en/career/jobs/), it doesnt work.

How can I accept both variants in the match url ?


Solution

  • You just need to change your parameters to match both en/career/jobs/ and en/career/jobs. You can use the following rules as a reference:

    <rule name="URL Test" enabled="true" stopProcessing="true">
        <match url="^en/career/jobs(.*)$" />            
        <action type="Redirect" url="https://www.example.com/newjobs" appendQueryString="false" redirectType="Permanent" />
    </rule>