Hello Friends, Today we will learn about “How we can redirect visitors to our HTTP website to HTTPS“.
If you have an SSL Secure Certificate installed on your website, you can easily redirect visitors to the secure version of your website(HTTPS) automatically. First, we have to know where your website is hosted.
Linux & cPanel
If you don’t have an .htaccess file in the root directory of your website, then you have to create a new file. If you don’t know how to create this, watch the video:
Once you create the .htaccess file in the file manager, just copy & paste this code into the .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
NOTE: If you already have an .htaccess file, then check these points
- Don’t duplicate RewriteEngine On
- Make sure the lines starting from RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.
If you are confused about how to add this code to the existing .htaccess file, then see the screenshot of a WordPress site below.


Windows & Plesk
Windows hosting accounts use the web.config file instead of .htaccess to handle redirections.
NOTE: If you don’t have web.config file, then the process will be same like .htaccess, just type web.config while creating a new file in file manager
Using the code below in your web.config file, you can automatically redirect visitors to your HTTPS version website.
<configuration>
<system.webServer>
<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="Permanent" url="https://{HTTP_HOST}/{R:1}" />
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/rule&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;<br />
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/rules&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/rewrite&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/system.webServer&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/configuration&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;
NOTE: If you already have a web.config file, then check these points
- Ensure you have sections (i.e., opening and closing tags) for:
~ system.webServer (which contains rewrite)
~ rewrite (which contains rules)
~ rules (which contain one or more rule sections)
Insert any of those sections that do not exist. - Insert the entire rule section, including match, conditions, and action, inside the rules section.
You May Like it
Discover more from Wordpress Tutorial for Beginner's
Subscribe to get the latest posts sent to your email.





2 thoughts on “HTTP to HTTPS Redirection Automatically Using .htaccess and web.config”
This helps IF the user types http://www.domain.com — it will take them to https://www.domain.com. However, if they just type domain.com, it still doesn’t route them. In my case, at least.
Hello Robert,
First of all, thank you so much for giving an interest in my blog post.
Secondly, you asked a good question, Let me explain.
This blog post is related to the redirection of HTTP website to HTTPS one. Either your website URL is with WWW or without WWW, your website URL always have HTTP. Browers Address bar never saw you http in front of your domain(www.domain.com or domain.com) name until you have https.
You have to update your DNS with both http://www.domain.com and domain.com
Please follow us and let me know your feedback.
Thanks