Force website visitors to use SSL (https) using .htaccess

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
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Subdomains

In CPanel go to Domains -> Subdomains. This will take you to the Subdomain Maintenance page...

DNS Nameserver Changes

If you purchased the domain from us please open a support ticket and we will assist you. Below...

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...