08 Apr 2020
These are common IIS redirect rules that I use in my website.
//Redirect to www
<rule name="redirect to www" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" /> </conditions> <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" /> </rule>
//Http to Https
<rule name="redirect to https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> </rule>
//Lowercase URL
<rule name="lowercase url" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" />
</rule>
//Root hit redirect to en
<rule name="redirect to en" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/en" />
</rule>
//Redirect old domain to new domain
<rule name="Redirect olddomain.com to newdomain.com" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^www..com$" />
<add input="{HTTP_HOST}" pattern="^olddomain.com$" />
</conditions>
<action type="Redirect" url="https://newdomain.com/{R:1}" redirectType="Permanent" />
</rule>
Reference: