IIS8 Redirect http/https and non WWW in one rule

13th February 2018
by InfiniteMonkeys

Simple IIS rewrite to redirect all non-SSL and non-www traffic in a single URL rule, just place in the web.config:

<rewrite>
<rules>
<rule name=”Force WWW and SSL” enabled=”true” stopProcessing=”true”>
<match url=”(.*)” />
<conditions logicalGrouping=”MatchAny”>
<add input=”{HTTP_HOST}” pattern=”^[^www]” />
<add input=”{HTTPS}” pattern=”off” />
</conditions>
<action type=”Redirect” url=”https://FQDN/{R:1}” appendQueryString=”true” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>

** Note you need the module installed first, reload IIS after installation.
https://www.iis.net/downloads/microsoft/url-rewrite