HTTP to HTTPS Redirect on IIS7

Redirecting all HTTP traffic to HTTPS for a single site on IIS7 is as simple as the following steps.

1. Install Microsoft URL Rewrite Module if not already installed

2. Install your SSL certificate as Normal.
(Note that you need to keep a hostname-less port 80 entry in the Bindings, as well as port 443 for SSL, in order for the redirect to work.)

3. Add the following XML to your Web.Config file. 

  <system.webServer>
    <rewrite>
    <rules>
      <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
      </rule>
    </rules>
    </rewrite>
 </system.webServer>

4. Do a IISRESET

5. Test the URL to ensure http redirects to https. Also test not entering a http at all, just the website host name.

6. Done.

Comments are closed