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 %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]

If your website is in a subfolder, use this code instead:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://yourdomain.com/folder/$1 [R=301,L]

Where yourdomain.com is your actual domain name and folder should be replaced with the name of the subfolder where your site is situated.

You can edit the .htaccess file either via FTP, or using with the File Manager availalbe in cPanel.

Was this article helpful?

Related Articles