How to force SSL/HTTPS with .htaccess

After having SSL enabled for your domain, you may want to route all your traffic to HTTPS rather than the non-SSL version, HTTP.  To do this, the easiest method is using Apache .htaccess handler to redirect your traffic to HTTPS on all requests. If you already do not have a .htaccess file you need to create on in your /public_html directory or if it exists, add the following code in it.

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


This will redirect all traffic to HTTPS for your domain name.

If you want to force subdomains to also redirect, then add the following line too, replace {subdomain} with your subdomain, eg. jobs.example.com

RewriteCond %{REQUEST_URI} !/{subdomain}$
Was this answer helpful?

Also Read

How to Resolve "cPanel Error: Your IP has Changed".

cPanel will sometimes throw out the error "IP address has changed!" while you're trying to...

How to Install AutoSSL certificate in cPanel

An SSL certificate on your website gives you the padlock icon in your browser, and this encrypts...

How to generate CSR in cPanel for SSL Certificate issuing

Follow these simple steps Login to cPanel (yourdomain/cpanel) Click SSL/TLS > Generate,...

Default files / folders of cPanel

Regular files & folders In a fresh cPanel hosting account, these are the files and folders...

First time login to Window Server with RDP

If you get the error message the first time you access Windows after installation, your client...