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

Folder and File Permissions

For the security of your websites, these should be your default permission settings:...

How to Enable PHP Error Reporting

If your application/script is not working as expected and you're not sure why, a great way to...

You need to Administer your WordPress sites

WordPress, in particular, powers over 40% of the websites on the internet. This makes it a...

How to set a secure password

Your password cannot be too strong, the more complex and long it is, the better! A combination...

How to use ClamAV Virus Scanner

To run a virus scan, follow these steps: Log in to cPanel On the Advanced tab of the...