Linux: Force Website from HTTP to HTTPS using htaccess

Recently web browsers will show a warning sign if your website is not secure with HTTPS encryption.
If you are hosted in Linux and users visit your website with HTTP protocol, even though you have HTTPS the website will appear as HTTP with the warning sign.

You may create a file or modify your existing htaccess (dotHTACCESS, there is a dot symbol infront of HTACCESS) file inside your website's root folder or PUBLIC_HTML folder.
Paste the following two lines of code in the beginning of your htaccess file, you can do this in the File Manager inside cPanel (if htaccess is hidden, click on the settings icon on the top right and enable show all files).

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

  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

Can I transfer my SSL certificate to you?

If you already have the SSL certificate, you can send the backup file (.pfx format) of the...

Windows: Export and import PFX file on IIS

PFX is one of the formats that Microsoft allows for SSL installation and contains both the SSL...

Windows: Generate CSR code in IIS

CSR (Certificate Signing Request) code is a set of encoded text that contains information about...

What is SSL?

SSL stands for Secure Socket Layer is the standard security technology developed by Netscape...

DirectAdmin: Install SSL certificate from Let's Encrypt

Please follow the steps below to install SSL certificate from Let's Encrypt in DirectAdmin...