How to Force SSL on all pages on your website 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.

 

 

  • 35 Users Found This Useful
Was this answer helpful?

Related Articles

My domain name is not registered with ZillionKingHost can I host my website at ZillionKingHost?

Yes you can host your website with ZillionKingHost.1. Check our hosting packages and  select the...

Termination of hosting accounts

Suspended accounts are terminated based on the billing cycle of the accounts as follows: For...

Why Was My Hosting Account suspended?

There are various reasons why your account was suspended. 1. It may have been suspended because...

How to Migrate from your Previous Host to ZillionKingHost

Migrating from your previous host to ZillionKingHost  can be a very smooth process or it can...

How to Block an IP Address

The .htaccess file is typically found in the root folder of your domain (where you would also...