Home How toASP.NET Force all traffic from HTTP to HTTPS using Web.Config file

Force all traffic from HTTP to HTTPS using Web.Config file

by Wikky
1342 views
force-http-to-https
force-http-to-https
force-http-to-https

Once you have setup your SSL the next thing is to redirect all traffic of your website from HTTP to HTTPS. By default your website is accessible from HTTP. And you can configure it by many ways at IIS, Application coding level or WEB.CONFIG file. The simplest way to do it at WEB.CONFIG level.

Open Asp.Net WEB.CONFIG file and Put following rewrite rule tags under the <system.webServer> tag.

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

Save and publish it on server. Now check your website will start loading at HTTPS.

Hope this works!


You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More