Jasinski Technical Wiki


Home Page
All Pages

Quick Search
Advanced Search »

Contributor Links

Create a new Page
File Management
Your Profile

Other Wiki Sections



Page History: Forcing SSL with a URL Rewrite Rule - IIS7

Compare Page Revisions

« Older Revision - Back to Page History - Newer Revision »

Page Revision: Tue, Sep 23, 2014, 9:36 AM


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). It can also be accomplished by added the following to your web.Release.config file.

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

1. Within IIS7 Manager, navigate to the site of interest > IIS group > URL Rewrite icon

2. Create a rule with the following settings

Match URL
Requested URL = Matches the Pattern
Using = Regular Expressions
Pattern = (.*)
Ignore case = unselected

Conditions (only one condition)
Logical grouping = Match All
Input = HTTPS
Type = Matches the Pattern
Pattern = off
Track capture groups across conditions = unselected

Action type = Redirect
Redirect URL = https://{HTTP_HOST}/{R:1}
Append query string = selected
Redirect type = Permanent (301)

SSL Redirect Rule Settings

SSL Redirect Rule Settings

Multiple Web Servers Behind a Load Balancer

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}" />

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