HTTP to HTTPS redirect on IIS
The requirement was simple. To redirect all HTTP traffic to HTTPS traffic. First thought that crossed my mind is - "Can't we do it with HTTP redirect?". After trying the approach, the site went into a infinite redirect loop. Pretty obvious! Right? After some googling, this is what I have done.
- Install URL Rewrite module from http://www.iis.net/downloads/microsoft/url-rewrite
- Add the following rule to your web.config. For more details about, doing the same from UI is explained @ http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/
<
rule
name
=
"Redirect to HTTPS"
stopProcessing
=
"true"
>
<
match
url
=
"(.*)"
/>
<
conditions
><
add
input
=
"{HTTPS}"
pattern
=
"^OFF$"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"https://{HTTP_HOST}/{R:1}"
redirectType
=
"SeeOther"
/>
</
rule
>
- Recycle Website
This gave me a great start on URL rewriting. Post this, I setup a proxy and written multiple rewrite rules on IIS. The below article by Jim van de Erve is very helpful.
Comments
Post a Comment
Feedback - positive or negative is welcome.