IIS - Redirect HTTPS to HTTP using URL Rewriting

Asked By Kapil Desai on 27-Jun-11 08:06 AM
Would like to Redirect users from HTTPS to HTTP using IIS URL Rewriting....
Jitendra Faye replied to Kapil Desai on 27-Jun-11 08:10 AM

There are several options for rewriting URL's on IIS, and users of IIS 7 are able to take advantage of Microsoft's own URL Rewrite module. In this guide we'll look at how you can use Microsoft's URL rewrite module to transparently redirect HTTP to HTTPS.

For this guide to work you'll need;

  • IIS 7 installed
  • Microsoft URL Rewrite Module installed
  • Create HTTPS bindings to your IIS website and assign certificate
  • Ensure Require SSL is NOT checked under SSL Settings for your website

Once you have this done you can simply copy and paste the following code between the <rules> and </rules> tags in your your web.config file in your website root directory.


<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>

From here all you have to do is save your web.config file and test that the redirection is working.
Kapil Desai replied to Jitendra Faye on 27-Jun-11 08:12 AM
Dude its http to https.....I doesnt work for https to http...
Reena Jain replied to Kapil Desai on 27-Jun-11 08:13 AM
hi,

check for the server variable {HTTPS}.

"Returns ON if the request came in through a secure channel (for example, SSL); or it returns OFF, if the request is for an insecure channel."


The condition, then, would be:

<add input="{HTTP}" pattern="off" />

http://msdn.microsoft.com/en-us/library/ms524602(VS.85).aspx

Hope this will help you