How to Automatically Redirect HTTP Traffic to HTTPS?

July 30, 2020 2:04 am

In 2021, its even more important to ensure that your website is served securely with proper SSL-encrypted connection for added security, PCI compliance, or accessibility. Its equally important to not only install the SSL certificate but force it on your website as well such that the website is never served insecure. The first stage for this starts with having a valid SSL certificate and a website that forces HTTPS on all calls.

Babal Host provides a free SSL certificate as a standard in all our web hosting plans. It's automatically installed and activated once you've added your domain and once the DNS for the same points to us. If the SSL certificate isn't installed automatically, you can refer to the following article for - How to install SSL certificate in my website? If you're still unable to resolve it, you can always open a support ticket from your client area, or connect with our friendly agents in our live chat.

Video for forcing HTTPS with the use of .htaccess:

Blog for forcing HTTPS with the use of .htaccess:

The easiest way to accomplish this is by forcing HTTPS with the use of .htaccess. Here's the step by step procedure for you to achieve this.

  1. Open File Manager from your cPanel or FTP client
  2. Open the folder "public_html" from either the left-hand side menu box of the folder block as in the main display block
  3. Find ".htaccess" file. If you're able to locate the file - skip to "Step 5" else click on Settings located at the top right part of the screen:
  4. On the box that pops out, check the box next to "Show hidden files (dotfiles)" and click on "Save":
  5. You should now be able to locate ".htaccess" in your File Manager. Select it and click on "Edit" as shown in the image to make changes to this file:
    Add the following line of code at the top of your .htaccess file and click on "Save":
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} [L,R=301]

Congratulations! Your website will now be served with forced HTTPS. Do ensure that all your links are converted to https to be able to see the full impact of the same. If you're using WordPress, you can refer to our article here on how to update all http links to https. This is how the website URL bar looked like before the code was placed:

This is how your website will look after the code is in place, and if you click on the padlock "secure icon" - this or similar view is what you'll see.