Redirect HTTP to HTTPS automatically in Linux / Cpanel

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.

Linux-based accounts use .htaccess files to handle redirection.

Note: If you need to create a .htaccess file, you can use your control panel's file manager.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

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


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.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Pages getting 500 error

TVMserver Linux cPanel Hostings uses SuPHP to secure PHP. suPHP is a tool for executing PHP...

Disabling Cache on Linux Server

You can disable caching of files by adding this code to the bottom of .htaccess <Files...

How to change my document root folder using an .htaccess file?

By default your main website is loaded from the public_html folder of your account. The...

Connection is insecure - SSL certificate issue

First you need to check whether SSL certificate is installed in your hosting account.  You can...