Search code examples
http-redirectiisweb-config

IIS 10 Redirect all urls from sub directory


After a site rebuild we are looking to redirect a number of old urls to there new addresses.

I have the rule below that works fine for the exact url:

https://www.example.com/property/subfolder/

But we would like everything underneath that directory to be redirected to the same place as well so the 3 urls below (and the numerous variations) should all get redirected:

https://www.example.com/property/subfolder/

https://www.example.com/property/subfolder/12309

https://www.example.com/property/subfolder?sort_by=price

Have tried a number of variations of this rule but none worked for anything other than the exact url. Any ideas of what I'm missing?

Thanks

    <rule name="Rewrite Rule new structure">
<match url="https://www.example.com/property/subfolder/$" />
 <action type="Redirect" url="https://www.example.com/properties/area/subfolder/" redirectType="Permanent" /> 
</rule>

Solution

  • Your parameter need to match the string after the domain name, you can try the below rule:

    <rule name="test" stopProcessing="true">
      <match url="^property/subfolder(.*)$" />
      <action type="Redirect" url="https://www.example.com/properties/area/subfolder/" redirectType="Permanent" />
    </rule>