Use IIS to Redirect HTTP Pages to HTTPS SSL Pages

7/28/2014 1:58:21 PM

The following IIS Rewrite Rule will redirect any non-HTTPS request to a HTTPS url. The config below is the websites web.config.

* You will need the IIS URL Rewrite Module installed.

* You will need to disable/uncheck the "Require SSL" checkbox under IIS -> Your Website -> SSL Settings

<!-- Web.config -->
<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>
	
...

Using Separate Rules File

<!-- Web.config -->
<system.webServer>
	
	<rewrite>
		<rules configSource="RewriteRules.config" />
    </rewrite>
	
...

<!-- RewriteRules.config -->
<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>