[How To] Redirect HTTP to HTTPS using | IIS | web config asp.net

HTTPS force re-direction


Today we are going to see, how to re-direct forcefully re-direct HTTP (hosted on 80 port in IIS) to HTTPS (hosted on 443 port). It is very simple for your asp.net web application. Just need some changes in your web.config file.

Redirect HTTP to HTTPS using web.config

Edit your web.config file and place the below code in your system.webServer tag.
<rewrite>
      <rules>
        <clear />
        <rule name="Redirect to https" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>

so the whole tag must be like below

  <system.webServer>
    <rewrite>
      <rules>
        <clear />
        <rule name="Redirect to https" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

Now your HTTP website will forcefully re-direct to HTTPS.
[How To] Redirect HTTP to HTTPS using | IIS | web config asp.net [How To] Redirect HTTP to HTTPS using | IIS | web config asp.net Reviewed by Tech Doubts on 2:23 AM Rating: 5

No comments:

Powered by Blogger.