IIS Rewrite Rules (force www to non-www and http to https)

  • Redirect www site to non-www. eg. I use the rule below for my own website. If user browses to https://www.indexedmind.com, redirect them to https://indexedmind.com
    <system.webServer>
    <rewrite>
    <rules>
    <rule name=”Redirect WWW to non-WWW” stopProcessing=”true”>
    <match url=”(.*)” />
    <conditions>
    <add input=”{HTTP_HOST}” pattern=”^indexedmind\.com$” negate=”true” />
    </conditions>
    <action type=”Redirect” url=”https://indexedmind.com/{R:1}” />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    
  • Redirect http request to https. eg. if user browses to http://indexedmind.com, force them to go to https://indexedmind.com
    <rule name=”Redirect to HTTPS” stopProcessing=”true”>
    <match url=”(.*)”/>
    <conditions>
    <add input=”{HTTPS}” pattern=”^OFF$”/>
    </conditions>
    <action type=”Redirect” url=”https://{HTTP_HOST}{REQUEST_URI}” redirectType=”SeeOther”/>
    </rule>
    
Advertisements

One thought on “IIS Rewrite Rules (force www to non-www and http to https)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s