Redirect HTTP to HTTPS

Programming, error messages and sample code > sample code
Redirecting all traffic from HTTP to HTTPS in IIS7 will make sure your users always access the site securely.

What you need to do to set the redirection from http to https is add the following url rewrite rule to your web.config file, then save it.

Please put the web.config file in the root folder of your website.
<?xml version="1.0" encoding="UTF-8"?>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
            <match url="(.*)" />
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
And now test the site by going to and making sure it redirects.