How to redirect website from HTTP to https in IIS?

If we install the SSL Certificate on a website, it is required to redirect the website from HTTP to HTTPS or it will be still accessible with insecure HTTP. In order to mitigate that, you can set URL Rewrite Rule in IIS. This will force the website to redirect to the https. Redirecting the website to the https is useful for Website SEO.

A user will enter the http://example.com in web-browser will be redirected to the https://example.com which will help to set a secure connection between user and website. Following are the steps to set the URL Rewrite Rule.

  1. Login to your server and Open IIS.

  2. Select the website and click on URL Rewrite.



  3. Click on Add Rule from the Actions tab.

  4. In the Add Rule Dialogue Box, click on Blank rule inside Inbound Rules.





  1. Set the below settings, inside Edit Inbound Rule.

  • Name: Add Rule Name.

  • Inside Match URL :

                (a)  Requested URL: Matches the Pattern

                (b)  Using: Regular Expressions

                (c)  Pattern : (.*)

                (d)  Ignore Case should be checked.

          

  1. Expand the Conditions Section >> Logical Grouping >> Match All

  2. Click on Add Button and it will open the box to add the condition.

  • Condition Input : {HTTPS}.

  • Check the Input String: Match the Pattern

  • Pattern: ^OFF$

          

  1. Click on Ok Button.

  2. Expand the Action Section.

  • Action Type: Redirect

  • Action Properties : https://{HTTP_HOST}/{R:1}

  • Append Query String: Checked

  • Redirect Type: Permanent (301)

  • Note: We have selected 301 Permanent Redirection here.

          

  1. Click on Apply Button from Actions.

  2. Now, we will check the added rule in web.config file of your website. To open these files. Select and Right Click on Website. >> Explore >> Open the web.config file

There will be following code inside your web.config file. In case there is no web.config file, you can create and put the below code inside web.config file and save it to your root directory.

          

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”HTTPS force”enabled=”true” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTPS}”pattern=”^OFF$” />
</conditions>
<action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

In Classic Windows VPS plan, do we get latest version of SQL and Visual Studio installed? Also do we get latest .Net framework?

While placing an order, you will get an option to select SQL server version and its edition....

Is HTML5 Supported in Your Servers?

Since HTML content has nothing to do with the web server, there are no special requirements...

How to Install Telnet Client in Window and Linux?

Telnet Client allows you to connect to remote and local computers via Telnet protocol. Telnet...

How to Open Ports in Firewall on Windows Server 2016?

Following article will assist you to open ports in Firewall on Windows VPS with Windows Server...

What is the database connection string for my website?

It is recommended that you take the help of your web developer to define the database connection...