How to Force SSL on all pages?

How to force HTTPS using the .htaccess file

To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.

Important: If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Be sure to replace www.example.com with your actual domain name.

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Make sure to replace example\.com with the domain name you're trying force to https. Additionally, you need to replace www.example.com with your actual domain name.

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:

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

Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folder with your actual domain name and folder you want to force the SSL on.

Was dit antwoord nuttig? 5 gebruikers vonden dit artikel nuttig

Gerelateerde artikelen

Cant Access My Site?

We receive lots of queries from our client saying that why i'm not being able to access my site....

500 Internal Server Error

Internal Server Error help, 500 error Internal server errors can be caused by a few different...

How to Transfer cPanel Accounts from another Server?

This tutorial will show you how you can create FULL BACKUP and remotely upload this to your new...

How to Switch Hosts?

Switching to a new host can be a very smooth process or it can be very complicated. Following...

How to Transfer Email Accounts and Messages Between cPanel Servers?

If you want to transfer the email accounts and messages for a domain from one server to...