How to force SSL with .htaccess?

To force the HTTPS connection on your website, add the following lines inside the website’s .htaccess file:

  1. Go to File Manager in your hosting panel
  2. Open .htaccess inside the public_html folder. If you can’t locate it, make sure to create or unhide it.
                      How to Locate an Open .htaccess File In Case You Didn’t find it?
                           If you are using cPanel, the process is more or less similar
                             1.Access File Manager -> public_html.
                            2.If you can’t find the file, go to the  Settings on the upper right menu and tick the Show Hidden                                          Files option to enable viewing.
                               IMPORTANT! This only applies to cPanel-based hosting platforms.

 

3. Scroll down to find RewriteEngine On and insert the following lines of code below it:

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

 

4. Save the changes.

IMPORTANT: Make sure that the line RewriteEngine On is not repeated twice. In case the line already exists, simply copy the rest of the code without it.

Was this article helpful?

Related Articles