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.
- Open IIS and click on the site name (example.com).
- 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“.
- Now double click on URL Rewrite and click on Add Rule from Action tab.
- Choose Blank rule in Inbound Rules and click on Ok.
- Give any Name in the Name field (like http to https). This is to remember or to know the rule type.
- 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.]
- 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. 🙂
- Now come to Action tab, and set Action Type to “Redirect“.
- In Action properties, Give the Redirect URL as “https://{HTTP_HOST}/{R:1}“. Again, do not add quote here.
- Now set the Redirect Type as “See Others (303)“.
- 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!
My name is Shashank Shekhar. I am a DevOps Engineer, currently working in one of the best companies in India. I am having around 5 years of experience in Linux Server Administration and DevOps tools.
I love to work in Linux environment & love learning new things.
Powered by Facebook Comments
Leave a Reply