Are you thinking of securing your website with an SSL Certificate?

If Yes, then you are the right track. Google is running tests to check if sites use SSL or not in their search ranking algorithms.

  1. Secure connection helps in building trust with the users.
  2. SSL certificate plays a vital role in improving your search engine rankings.

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.

Now that you have an SSL Certificate, the next step is to redirect HTTP to HTTPS for safety, accessibility or PCI compliance reasons. Before we move onto the redirecting process, you need to edit the .htaccess file.

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.

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.


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.

Steps to Edit .htaccess File

There are specific instructions in the .htaccess file that informs the server how to behave in particular cases and directly affects your site functionality. Two primary directives in a .htaccess file are Redirects and Rewriting URLs.

DIfferent ways to edit the .htaccess file are:-

  1. Edit the file on your computer and upload it to the server using FTP.
  2. Use “Edit” mode in the FTP program that allows you to edit a file remotely.
  3. Make use of a text editor and SSH to edit the file.
  4. Use the File Manager in cPanel to edit the file.

Editing .htaccess in cPanel File Manager

Note- Backup your website in case something goes wrong.

  1. Login to cPanel
  2. Files > File Manager > Document Root for:
  3. Now select the domain name you want to access
  4. Check “Show Hidden Files (dotfiles)”

1. Login to cPanel

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

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

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.

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.

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.

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.

How to Redirect http to https In Apache?

1. Redirect All Web Traffic

If you have existing code in your .htaccess, add the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

2. Redirect Only a Specific Domain

For redirecting a specific domain to use HTTPS, add the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

3. Redirect Only a Specific Folder

Redirecting to HTTPS in a particular folder, add the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$$1 [R,L]

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the real folder name.

How to do http to https redirect In Nginx?

Note- Take a backup of nginx.conf or default.conf file

  1. Login to Nginx web server
  2. Add return 301 https://$server_name$request_uri in server directive.
  3. Save the file.
  4. The last step is to restart your Nginx Web Server.

Phew! It’s done.

Congratulations, you have redirected http to https successfully.


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.

Think it was useful? Share this article to help them come on HTTPS