How to Force HTTPS Using the .htaccess

Force HTTPS Using .htaccess

Force HTTPS

If you have Purchased an SSL Certificate and have setup your SSL within cPanel then you can use this method to Force Visitors to use SSL.

If you have not yet purchased an SSL Certificate you can purchase one “Here

We have also created a guide on how to setup your SSL Certificate after your purchase. You can follow our guide “Here

Also Most importantly after you have purchased and setup your SSL you will need to Install Your SSL Certificate into cPanel. You can find our guide “Here

Force HTTPS Using .htaccess

after you have completed the above tutorials or if you have already installed your SSL Certificate then please continue below.

Forcing visitors to use your SSL can be Achieved through your .htaccess file using mod_rewrite.

Where To Locate Your .htaccess File

your .htaccess file is found within your public_html folder within your hosting account. it is usually always located in the root directory of your website.
The picture below is taken from FileZilla FTP.

htaccess

Redirecting All Web Traffic with .htaccess

To force web traffic to use HTTPS you will need to insert the following code into your .htaccess file within your websites root directory.

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Now you have saved the file and uploaded back into your web root directory you will be able to go your website “e.g https://www.yourwebsite.com” and you should be able to see a “Green Padlock” in your browsers address bar.

If you have run into a privacy issue within your browser there could be a few issues and you will need to go back and double check that you have Installed your SSL Certificate correctly.

And Make sure that you have edited and uploaded the .htaccess file after entering the code above.

If all else fails please feel free to contact us via a “Support ticket”. and we will do our best to assist you with any problems that may occur.

We hope this How-to has helped you. if you think I have missed anything please feel free to leave a comment below

Thanks.
Simon M.
Typical Hosting

Simon. M