Jasinski Technical Wiki


Home Page
All Pages

Quick Search
Advanced Search »

Contributor Links

Create a new Page
File Management
Your Profile

Other Wiki Sections



Forcing SSL with a URL Rewrite Rule - IIS7

Modified on Mon, Jan 30, 2017, 9:28 AM by Administrator Categorized as Windows (OS, IE, IIS, and MSMQ)


Frequently when you have a site that uses SSL, you want to force the use of SSL on all pages. Thus, when a user navigates to an http:// . . . address on the site, you would like them redirected to the equivalent https:// . . . address. This article describes how to do this within Internet Information Services 7


Single Web Server

This procedure will work with a single web server (i.e., no load balancer), but you MUST HAVE THE URL REDIRECT MODULE for IIS installed!

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

Multiple Web Servers Behind a Load Balancer - Site Does NOT Use SignalR

NOTE: This will break SignalR. See below for how to force SSL for a site that uses SignalR.

Add the following to your web.Release.config file

  <rewrite xdt:Transform="Insert">
      <rule name="HTTPS rewrite behind ELB rule" enabled="false" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
          <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
        <action type="Redirect" redirectType="Found" url="https://{SERVER_NAME}{URL}" />

Multiple Web Servers Behind a Load Balancer - Site Uses SignalR

1. Setup a dummy site with a binding for http://yoursite.com

2. Root folder should have an index.html file

3. The web.config file should contain the following.
<?xml version="1.0" encoding="UTF-8"?>
        <httpRedirect enabled="true" destination="https://yoursite.com" httpResponseStatus="Permanent" />

4. Within Amazon Web Services, edit the listeners on the load balancer, to (a) remove all HTTP and HTTPS listeners, and (b) add two listeners as follows.

Load Balancer Protocol/PortInstance Protocol/Port
SSL (Secure TCP):443SSL (Secure TCP):443

  Name Size
- IIS7 - SSL Redirect.png 20.87 KB
- TcpListeners.png 15.81 KB

ScrewTurn Wiki version Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2023, Patrick Jasinski.