How to Redirect HTTP to HTTPS Automatically Step by Step


Using HTTPS protocol is very important for our website. If you have any transaction process on your website then it is obvious to use HTTPS protocol. For that, you have to redirect http to https.

You can easily redirect http to https using .htaccess file. I will give you the step-by-step guide to do that. There are only a few steps to follow.

Read also: How To Create A 301 redirect Properly Complete Guide.

When you redirect HTTP to HTTPS

The HTTPS protocol is also useful for Google ranking. If you have SSL certificate, this will improve your ranking in Google. Therefore, you can realize its importance.

However, the question is when you should redirect http to https.

After installing SSL certificate, you cannot visit https version of your website. If your visitor types your domain name, they see http version.

In this case, you need to redirect http to https automatically.

Pre-requisite

To redirect http to https, you must have SSL certificate install on your website. I guess most of the hosting providers provide free SSL certificate.

If you are using shared hosting, it is very easy to install free SSL on your website. You can contact your hosting support to install it. They will help you to do so.

How to redirect HTTP to HTTPS

Here, we are going to redirect HTTP to HTTPS using our .htaccess file. We will complete this whole process in 3 easy steps. You have to use some code inside your .htaccess file for that. However, don’t worry I have a backup for you.

I will provide all the code necessary to complete this process. You can copy and use them.

These easy 3 steps are:

  1. Login to cPanel
  2. Open .htaccess file
  3. Copy and paste the code in .htaccess file

##1. Login to cPanel

First, log in to your cpanel by typing your domain name with /cpanel at the end. For example https://domainname.com/cpanel

Because you are going to use .htaccess to redirect http to https. Find your “File Manager” option and go inside.

cpanel file manager

##2. Open .htaccess file

Now click on the “public_html” folder. If your website is installed in the root folder then you will find all the files inside this public_html folder. Otherwise, go to the specific folder inside public_html where your website is installed.

go to public_html

Now find out “.htaccess” file in this folder. If you don’t find it that’s ok. Click on “Settings” at the top right corner.

This will open up a new popup. Here you have to select “Show Hidden Files(dotfiles)” and click on save.

show hidden files

Now probably you will find .htaccess file if you have one. If it does not show up then create a .htaccess file by clicking “File” option at the top left corner.

Right click on your .htaccess file then click “Edit”. This will open up a new popup. In this popup, you have to click “Edit” again. Now you will get your .htaccess file opened on a new tab.

open htaccess file

##3. Copy and paste code in .htaccess file

I believe your .htaccess file is opened on your computer. So it is time to write some code. You have to copy and paste 3 lines of code in this file to redirect http to https.

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Just copy these 3 lines of code and paste at the very top of your .htaccess file. In addition, don’t forget to save your .htaccess file after doing all these changes.

Now click on “Save changes” button at the top left corner to save your .htaccess file.

Now type your domain name in your browser without using https at the beginning. I believe it will redirect to https automatically.

Congratulations, you have redirected http to https successfully.

Conclusion:

We have learned when and how to redirect http to https automatically using .htaccess file. I hope you have got a clear idea of how to use this. I have given you the code just use it and you will get your work done.

The HTTPS protocol is very important in Google ranking. So install an SSL certificate and then use https protocol for your website.

So if you need any assistance with this tutorial, leave a comment below and I will try to help you out!! I will look forward to your opinion in the comments section below.

You can subscribe to our newsletter. I always provide the latest update about my new contents that may help you. Please share this post with your friend if it is helpful for you. So that they can also learn How to redirect HTTP to HTTPS automatically for their websites.

You may also like:

⇒ How To Create A 301 redirect Properly Complete Guide

⇒ How to Submit Sitemap to Google Search Console Today

⇒ 27+ Best Free WordPress Themes [For All Websites]

⇒ World’s 10 Best Websites to Earn Money Fast

⇒ How to Backup & Restore website with UpdraftPlus



I am Robin. Founder of "WorldTechis" community. It is the Largest online learning platform, here you can learn Web development, programming and advance Wordpress tips and tricks. As a professional developer, here I provide all necessary tips related to Programming & Wordpress. Like my Facebook page WorldTechis for the latest update or contact me - [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *