Force website visitors to use SSL (https) using htaccess

If you get the message in web browser that your website is "not secure" (not showing the lock icon) then try the instructions below.

UPDATE: This is now a setting in CPanel at Domains > Domains (enable "Force HTTPS Redirect")

This will redirect website users from non secure HTTP to secure HTTPS.

CPanel provides free SSL, so it is wise to ensure your visitors use it by enabling "Force HTTPS Redirect".

If this does not work try the manual htaccess method below.

-----------------------------------------------------------------------------------------------------------------------------------------------------------

To force all connections to use SSL create a blank text file (in the root folder) named .htaccess (with period at beginning) using the CPanel File Manager.
You may find the .htaccess file already exists in which case you can just add to it.
In this file paste the text below: (replace www.example.com with your domain)

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

Port 80 is the port used for all web traffic for web pages.
Files starting with a period are "invisible" files.
You may need to set the CPanel File Manager to show invisible files in the Settings button (top right).

Other Examples:

The code can be modified to pertain to a specific domain only:

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

Replace www.example.com with your info.

... or a specific folder only:

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


Replace foldername and www.example.com/foldername with your info.


  • SSL, htaccess
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Subdomains

In CPanel go to Domains -> Subdomains. This will take you to the CPanel subdomain page where...

Addon Domains

You cannot create a CPanel Add-on Domain until the DNS for the domain you are trying to add has...

Park a Domain

In CPanel go to Domains -> Aliases The Domain needs to be registered and DNS Nameservers set...

Are your IP addresses Canadian based?

By default IP Addresses and servers are based in Canada, but can be based in the US upon...

Domain Slammers - watch out for them

A "Domain Slammer" attempts to transfer your domain registration to them by fooling you into...