Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2

All the random crap I spend all day long figuring out.
Post Reply
User avatar
Site Admin
Posts: 54
Joined: Tue Jan 06, 2009 9:25 pm

Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2

Post by syntax » Wed Jan 22, 2014 4:03 pm

From ... write-2-0/

Doc is wrong about using "Redirect URL: https://{HTTP_HOST}/{R:1}" though. Using https://{HTTP_HOST}{REQUEST_URI} is better.

-Add blank url rewrite rule under directory you want to start at
- Enter “Redirect to HTTPS” in the name field.
- Next we will configure the first configuration pull down box called “Match URL”, on the right side of “Match URL” press the down arrow to expand the box.

Requested URL: Matches the Pattern
Using: Regular Expressions
Pattern: (.*)

Condition Input: {HTTPS}
Check if input string: Matches the Pattern
Pattern: ^OFF$

Action Type: Redirect
Redirect URL: https://{HTTP_HOST}{REQUEST_URI}
Redirect Type: See Other (303)

My resulting web.config:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
                <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                        <add input="{HTTPS}" pattern="^OFF$" />
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" />

Post Reply