Tuesday, March 7, 2017

[ASP.NET] Redirect HTTP request to HTTPS

 ASP.NET    IIS     HTTPS     SSL


▌Redirect http request to https


▋Step1. Install URL Rewrite to IIS

Download URL Rewrite extension or install it from Web PI (Web Platform Installer).


▋Step2. Set rewrite rules in Webconfig

Add the following rewrite rule into webconfig.

<system.webServer>
  <rewrite>
    <rules>
      <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>
    </rules>
  </rewrite>
</system.webServer>


No comments:

Post a Comment