Web Hosting

How to force HTTPS with the .htaccess file


Nowadays security is extremely important for both businesses and the end user.  There is a wide variety of security protocols to use but one of the most simplest yet necessary forms of online security is using SSL certificates. SSL stands for Secure Sockets Layer and is used as security for online communications. When your browser connects to a website the SSL certificate allows an encrypted connection. For example, to keep your luggage safe when travelling, you would put a padlock on.


1.  Finding your .htaccess file
To start with, you need to locate your .htaccess file. Depending whether your using an FTP client or an online File Manager like cPanel, you will have to do different steps:

If you’re using an FTP client, simply go to your websites root directory (usually public_html) and open the .htaccess file. If you cannot see one, you’ll need to create a new file and name it “.htaccess”.

If you’re using cPanel, login to your cPanel account and open up the File Manager. Click on Settings in the top right and make sure the “Show Hidden Files (dotfiles)” checkbox is ticked. After that go to your websites root directory, select the .htaccess file and click on Edit.

2.  Editing your .htaccess file
Now you have your .htaccess file open to edit, simply paste the below code in there. Ensure that you don’t repeat “RewriteEngine On” in the file:

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

2.  Saving your .htaccess file and testing
After you have pasted the above code you can save the file. When you head to your website through http (e.g. https://domain.com) you should be forced to using https (https://domain.com).


It’s as simple as that! All your website traffic should now be forced to use https and go through your SSL certificate. If you need any further help please feel free to use the community forum and myself or another user will help you out!

Related Tutorials