How to Redirect HTTP to HTTPS Using .htaccess [cPanel]

How to Redirect HTTP to HTTPS Using .htaccess [cPanel]

Are you confused as to how to redirect HTTP to HTTPs using .htaccess?

It sounds like a job that you might need to hire someone to do for you.

But what if I tell you that you can do it all by yourself!

Wouldn’t it be great that by the time you finish reading this article you will be an expert on how to redirect HTTP to HTTPs?

Sounds a little far-fetched but I know we can do this together.

In this article, I am going to break everything down stepwise, so you know what to do when you reach a specific page.

Sounds fun, right?

Let’s dive right into it.

Just follow the steps as mentioned and you will get the desired result you are aiming for.

But before we start, let me explain to you all the terms used in this article.

Also Read: FlyingPress Review: The Best Caching & Optimization Plugin

Redirect HTTP to HTTPS

Understanding the basics:

  1. HTTP: Hypertext Transfer Protocol (HTTP) is a request-response protocol that gives the user a way to converse with HTML files by transmitting hypertext messages between a web browser and a website.
  2. HTTPS: Hypertext Transfer Protocol Secure is a secure version of HTTP. It is encrypted to increase the security of data transfer.
  3. SSL Certificate: SSL certificate (Secure Sockets Layer) gives a type of digital certification to a website that provides authentication and enables an encrypted connection to a web browser.

When installed it activates a secure connection along with the HTTPS protocol and lets secure connection from a web browser to a search engine. Thus, a website needs to have an SSL certificate to redirect from HTTP to HTTPS. 

This is a little cheat sheet for enforcing SSL for your main domain / Startup Hosting

Prerequisites:

Now, I am going to guide you through the fastest way that would help you redirect HTTP to HTTPs overnight without losing your organic traffic.

1. Prepare your website for the redirect

Before you start to redirect HTTP to HTTPs, replace all internal absolute paths on your website with relative ones.

 2. Choose SSL Certificate

There are different types of SSL certificates available at your disposal these days. So I would recommend going to the one that is the most suitable for your website. 

Choosing the correct SSL certificate helps redirect HTTP to HTTPs smoother and easier.

3. Avoid Losing traffic

  • Update your Robots.txt file
  • Set 301 redirect (temporary redirect)
  • Create a new profile at Google Search console

After going through the above-mentioned steps, you are now ready to redirect HTTP to HTTPs.

Now that you have tackled one of the most crucial parts, the process of redirect HTTP to HTTPS is going to be very easy for you. 

Also Read: TasteWP Review: Free WordPress Hosting to Test Plugins & Themes

How to Redirect HTTP to HTTPS Using cPanel

  • Login into cPanel
Redirect HTTP to HTTPS using cPanel-1
  • Click on Domains
Redirect HTTP to HTTPS using cPanel-1
  • The Domains page will have a toggle where you can redirect the HTTPS on or off. I would recommend leaving that on. If the domain does not have an SSL installed, you might not have the option to enable HTTPS To get the option, make sure the SSL certificate is installed. 
Redirect HTTP to HTTPS using cPanel-1

This is one way to get a domain to use HTTPs.

For you to redirect all your traffic to use HTTPs, edit the codes in .htaccess file

How to Redirect HTTP to HTTPS Using .htaccess

If you’re someone who doesn’t have cPanel or who is not using shared hosting then you can easily redirect using .htaccess and this method will work on Apache and LiteSpeed servers.

What is .htaccess

htaccess file: Hypertext Access file has a certain set of instructions/directives that inform the server on how to behave in certain situations which directly affects the functioning of a website.

How to edit a .htaccess file?

  • Edit the file on your desktop and upload it on the server using FTP (File Transfer Protocol)
  • The edit mode in the FTP program allows you to edit a file remotely.
  • Use an SSH and a text editor to edit the file.
  • Use the File Manager in cPanel to edit the file.
Redirect HTTP to HTTPS using cPanel-1

I would recommend that you backup your website; if anything goes wrong in the process of editing the .htaccess file you can get back to the backed-up version of the website.

Let us begin with how to edit a .htaccess file using the File Manager in cPanel.

Also Read: How to Fix WordPress Not Showing ‘Add New’ Plugin & Updates Option

How to edit .htaccess in cPanel’s File Manager?

  • Open File Manager
  • Login to cPanel
  • Look for Files a File Manager a Document Root for:
  • Click on settings and then enable Show Hidden Files (dotfiles)
Redirect HTTP to HTTPS using cPanel - 3
  • Click on the ‘Go’ button
Redirect HTTP to HTTPS using cPanel

The File Manager should open in a new tab or a new window.

  • In the list of files, look for ‘.htaccess file’
  • Click on the icon for .htaccess file and then proceed to click on the ‘code Editor’ icon on the top of the page. (Alternatively, you can right-click on the file and click on ‘Code Edit’ on the menu.)
Redirect HTTP to HTTPS using cPanel 5
  • A dialogue box may appear asking you about encoding. Click on the ‘Edit’ button and continue.
Redirect HTTP to HTTPS using cPanel
  • The editor should open a new window
  • Then you need to paste the below-given code.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Edit the file according to your preference.
  • Click on ‘Save Changes’ in the upper right-hand corner when done.
Redirect HTTP to HTTPS using cPanel
  • The changes are now saved. Make sure to test your website to check if the changes are giving the desired effect. 
  • Once you have achieved the desired result, click on ‘Close’ to close the window. 

Here’s a few more command which will help you to redirect your website.

Redirecting all website traffic

Add the following to your existing .htaccess file.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirecting of a Specific domain

Add the following to redirect a specific domain to use HTTPs.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirecting to a specific Folder

Add the following when redirecting to HTTPs on a specific folder.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

Just copy the given codes and paste it on the backend.  

Your website is now successfully redirected from HTTP to HTTPs.

Important note: Replace ‘your domain’ with the name of the domain you want to redirect HTTP to HTTPS wherever necessary. And in the case of ‘/folder’ with the name of the actual folder.

Share on:

I am the founder of WebVerge. I have 5+ years of experience in WordPress. I always write about the things I am obsessed with tech, WordPress, and SEO. I am also a Digital Marketing trainer at IIDE.

Leave a Comment