Redirect my site to HTTPS in cPanel / Linux

If you have a secure SSL on your site, you can automatically redirect visitors to the secure (HTTPS) version of your site to ensure that their information is protected.

The way visitors are redirected depends on the type of hosting you have .

 Note: These instructions do not apply to WordPress installed in cPanel. For more information, see the topic


Linux-based accounts use files .htaccessto handle redirection.

If you do not have a file .htaccess:

Start by creating a file .htaccessin the public_html or webroot folder Within the file .htaccess, you can use the following code to redirect visitors, provided you have not already set up a file .htaccess:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$$1 [R,L]


RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you host multiple sites in the same account, you need to make sure that you have set up a file .htaccessin the directory of the site on which an SSL certificate has been issued. You need to replace with your domain name to run the sample code.

If you have a file .htaccess:

  • Do not make a copy of it RewriteEngine On.
  • Make sure the lines begin with RewriteCondand RewriteRulelie immediately after the existing ones RewriteEngine On.
  • cpanel, website, redirect, linux, htaccess
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to Install cPanel and WHM in CentOS 7

Installation of cPanel in CentOS 7 1. Ensure that your server has a standard hostname (FQDN or...

How to install WordPress through cPanel

Install WordPress with simple steps We link to the Magic Streams website and then go to the...

Redirect my WordPress website to HTTPS for cPanel hosting

After your SSL certificate is installed on your cPanel (Linux) hosting account, there are some...

How to Update cPanel License Key / Run License Script

To run the cPanel License Key update script (perhaps if you've upgraded from a trial license, or...

How to Install WHM/cPanel on RHEL or CentOS VPS

To install cPanel, run the following commands while logged in to your VPS as the root user: # cd...