IIS Rewrite Rule for adding versioning to the url if not found

Viewed 18
1 Answers

if the requested api link don't contain api/v1

You can use the parameter ^home$ to make the requested url match only home, this way api/v1 is not contained.

<rewrite>
  <rules>
     <rule name="Test" stopProcessing="true">
        <match url="^home$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www.domainname.com$" />
          </conditions>
        <action type="Redirect" url="http://www.domainname.com/api/v1/home" appendQueryString="false" />
     </rule>
  </rules>
</rewrite>

Body cannot contain mydomain, so i use domainname instead of it.

Related