Redirect my website to HTTPS in cPanel/Linux

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

How you redirect traffic depends on the type of hosting you have.

Note: These instructions do not apply to WordPress installed on cPanel.

If you do not have a .htaccess file:

Start by creating a .htaccess file in your public_html or webroot folder. Inside of the .htaccess file, you can use the following code to redirect visitors as long as you do not already have a .htaccess file set up:

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

If you are hosting multiple websites on the same account, you will need to make sure that you have a .htaccess file set up in the directory of the website that has a SSL certificate issued.

Warning: You need to replace coolexample.com with your domain name for the sample code to work.

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.
  • https
  • 22 Users Found This Useful
Was this answer helpful?

Related Articles

Custom cPanel and Webmail URL

Your clients will need to access cPanel to allow them to setup e-mail addresses, access webmail,...

How do I add another domain to my Hosting Account?

To add a new domain to your existing hosting account: 1. Log into your cPanel control panel2....

Setting up an Email Forwarder in cPanel and Webmail?

Email forwarding redirects incoming messages from one email address to a different email address....

How do I reduce the amount of disk used space?

Make sure you're not leaving email on the server. ?This includes drafts and trash. Make sure...

Powered by WHMCompleteSolution