How to redirect HTTP to HTTPS using htaccess in cpanel, automatically redirect http to https, htaccess, cpanel, how to force https on website,

How to redirect HTTP to HTTPS

Mostly you will note that once you purchase your website domain the URL (universal resource locator) displayed in your search bar in the browser loads with HTTP with a warning padlock being at the start. For example, if you visit, you will see that the not secure warning is displayed before the URL in the search bar as shown below

How to redirect HTTP to HTTPS using htaccess in cpanel

And when you copy the URL you will notice that it has an http prefix other than https

In this article, we will focus on how to automatically redirect HTTP to HTTPS in Cpanel using htaccess. By default, all hosting providers assume that you have the knowledge to work around your Cpanel that’s why you find that like this task you have to do it on yourself though most of them provide documentation on how to achieve it though for some developers it may not be straight forward to understand. This article will simplify this task and ensure that you learn easily and in a simple way.

There are two reasons why your website domain URL may load with HTTP other than HTTPS

  1. Either you do not have SSL installed.

SSL or Secured Socket Layer is a standard way accepted in data transmission systems that keeps an internet connection secure by safeguarding any sensitive data that is being sent between two systems and prevents hackers from reading and modifying any information transferred, including potential personal details.

If SSL is not installed in your website system, the URL will load with an HTTP prefix warning you that your site is not secure and it may be under attack at any given time

The solution to this is ensuring that you have an SSL certificate installed on your website.

    2. Or you have not redirected your website domain to only use HTTPS

This means that you may have SSL installed but someone may load your site with an HTTP prefix, this means when the person uses HTTP it will use the HTTP and show the warning message that your site is not secure. To avoid this, we shall show you how to redirect HTTP to HTTPS always so as to avoid the site's not secure warning.

To begin on the process of automatically redirecting HTTP to HTTPS,

  • Login to your Cpanel which is the server space provided when you purchased the hosting space.

In Cpanel, this is accessed by adding /cpanel suffix after your domain name, for example in my domain, the Cpanel login link will be
  • Add your username and password to log in
  • After login in, head to the files section and click file manager

How to redirect HTTP to HTTPS using htaccess in cpanel

  • Click on public_html
  • Once inside the public_html, the file called htaccess is located in this location which will be used to hold the configuration codes for redirecting HTTP to HTTPS

Htaccess is a file in Cpanel that holds configuration or instructions that directs what your site does.

Htaccess is not visible by default as it is a configuration file and in Cpanel configuration files have a . (dot) prefix so the htaccess file will be .htaccess.

To access .htaccess file,

  • In the public_html folder, click the settings button at the top right
  • Check show hidden files

How to redirect HTTP to HTTPS using htaccess in cpanel

  • The page will reload and the htaccess file will be visible
  • Open it by right-clicking it and selecting edit


To ensure that the redirection happens, add the below code inside the htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ https://www.$1 [R=301,L]


Replace mydomain with your domain URL.

Click save

The code above will force those instructions to the front side and once you reload the URL, the domain will load with https other than http as shown below

How to redirect HTTP to HTTPS using htaccess in cpanel

You will notice that the warning padlock and message will be replaced with a green padlock which when clicked it will display that the site is secure.


In the above discussion, we have highlighted what http and https does and the situation in which each scenario is encountered. We have shown the process of redirecting http to https.