Redirect non https urls to https with www

How to force HTTPS using a web.config file

This example shows how to Redirect example.com and www.example.com to https://www.example.com

You need to add this rules to your web.config file
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”CanonicalHostNameRule1″ stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^www\.example\.com$” negate=”true” />
</conditions>
<action type=”Redirect” url=”https://www.example.com/{R:1}” />
</rule>
<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>
</rules>
</rewrite>
</system.webServer>
</configuration>

facebooktwittergoogle_plusredditpinterestlinkedinmail

LEAVE A COMMENT