How to force SSL with .htaccess

You can force an HTTPS connection on your website by adding these rules in your website's .htaccess file:

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


The .htaccess file needs to be located inside the site's document root folder for example /home/your_username/public_html/.htaccess. If your website is in a sub folder, then the .htaccess should be placed in the corresponding sub folder.
You can create or edit the .htaccess file either via FTP or using with the File Manager available in cPanel.


  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

What is Softaculous?

Softaculous is a commercial script library that automates the installation of commercial and open...

How to upload (Linux Hosting) ?

In this tutor you're about to learn how to upload your website content via FTP client software...

What is www or public_html folder?

Please note that " www"  is just the symbolic link or just a mirror to the public_html directory....

What is .htaccess?

The .htaccess file can be placed in one or more of your /home/user/public_html subdirectories....

How to enable 'register_globals' ?

Since we upgrade all our Linux server to suphp enable, The php_value or php_flag configured will...