Redirect Rules


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>

Reference:

comments powered by Disqus