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=".*" />
    <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
  <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />

//Http to Https

 <rule name="redirect to https" stopProcessing="true">
      <match url="(.*)" />
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />

//Lowercase URL

<rule name="lowercase url" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" />

//Root hit redirect to en

<rule name="redirect to en" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/en" />


comments powered by Disqus