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

Windows: Generate CSR code in IIS

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

Windows: Force website to HTTPS using web.config

Latest web browser will show your website as "insecure" when a visitor visit your site via the...

Website Shows Mixed Contents Warning (http & https)

Nowadays, it is recommended for users to enable SSL on their websites.However, on some cases, the...

DirectAdmin: Install SSL certificate from Let's Encrypt

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

Windows: Installing SSL certificate in IIS

SSL certificate need to be installed on the server where the CSR was generated, this is crucial...