Set Redirection from HTTP to HTTPS in IIS

Set Redirection from HTTP to HTTPS in IIS

Hello Friends,

I am back with another topic. From now onwards, you will get new post update every week. Make sure you subscribe to this blog.

I have seen that many users feel difficulty in setting the redirection of the site from one URL to another. Let’s say, I have installed SSL on my site: beanexpert.co.in and I want my user to get the secure site i.e. with https protocol, then we need to set the redirection from HTTP to HTTPS protocol, so that whenever my user tries to access the site beanexpert.co.in, they will get redirected to https://beanexpert.co.in.

Setting this type of redirection is very easy in Linux server, however setting the same thing in Windows server requires little knowledge and effort. If you have a control panel, like cPanel, Plesk, then this redirection can be easily set. However, if you do not have a control panel, then it becomes a tough task to set it.

In this post, I will show you how you easily set the redirection of a website in Windows (IIS).

If you would like to set redirection of your site from http to https and if you do not have any control panel, then follow the below steps to set it in IIS in Windows server.

  1. Open IIS and click on the site name (example.com).
  2. Search for URL Rewrite option. If it is not present, then you have to install it. The installation is very simple. You can install it from IIS, click on the Web Platform in the Management Section of the site. However “Web Application” is not present in some of the IIS. In this case,  Just the package from the URL: https://www.iis.net/downloads/microsoft/url-rewrite and execute it. Once it is installed, restart the IIS application (reopen the IIS). You will now see the option “URL Rewrite“. BeAnExpert_Redirection
  3. Now double click on URL Rewrite and click on Add Rule from Action tab.
  4. Choose Blank rule in Inbound Rules and click on Ok.
  5. Give any Name in the Name field (like http to https). This is to remember or to know the rule type.
  6. In the Pattern field, add “(.*)” (without quote). [If you want to set up redirection for a single domain and not for all, give the domain name in the pattern field for which you want to set the redirection.]
  7. Now in Conditions, click on Add. Now in Condition Input, give “{HTTPS}” and in Pattern, give “^OFF$” and click Ok. Make sure you are not adding a quote in any field. I have added here quote to show/highlight the content to do. 🙂
  8. Now come to Action tab, and set Action Type to “Redirect“.
  9. In Action properties, Give the Redirect URL as “https://{HTTP_HOST}/{R:1}“. Again, do not add quote here.
  10. Now set the Redirect Type as “See Others (303)“.                                                                                                                                             BeAnExpert_redirectionBeAnExpert_redirectionBeAnExpert_redirection
  11. Now click on Apply. Your new rule is created and your site will now redirect from http to https.

The above redirection sets the redirection of a website let’s say: beanexpert.co.in and its all alias domain. If you want to set the redirection for only one website, then please follow the below steps.

 

Set redirection to one domain only:

If you want to set the redirection for a domain and not for its alias domain (in case of Plesk panel), then add the below code between the section  “system.webServer” (if you do not want to set the redirection from IIS) in the web.config file.

————————

<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?example.com" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>

————————

Put your domain name in pattern field (replace example.com to your required domain name, let’s say: examplealias.com). Then it will redirect only examplealias.com.

Hope you like this post. Feel free to comment your query and feedback in the comment section.

Thank you!

Powered by Facebook Comments

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.