Do you want to ensure that visitors to your website should access it through an SSL-encrypted connection? If yes, you must know that having an SSL certificate is not enough if your website gets accidental visitors who are using an unsecured connection. This problem can be solved by redirecting HTTP to HTTPs in .htaccess on your website which means all visitors to your website are directed to https. The .htaccess file contains directives that tell the server how to behave in certain scenarios and directly affects how your website functions.

Using SSL Certificate is Important!

An SSL certificate is a data file hosted in a website’s original Hosting server. The certificate’s installation means that your website is available over HTTP and HTTPs both. However, the latter is preferred as it encrypts and secures your website’s data. It is recommended that you require all visitors to your website to access it through a secure connection. This is important because search engines may penalize you for not using SSL. They even give priority to search results with secure connections over the ones that do not have a secure connection. Therefore, forcing SSL via .htaccess is recommended.

How to Ensure Greater Security?

To ensure greater security you should force HTTP to HTTPs on .htaccess on all pages. Here we talk about how to redirect HTTP to HTTPs in cPanel or htaccess. The .htaccess file is a configuration file which is hidden by default but can be viewed by clicking on view hidden files in the file manager section of cPanel.

Use the code editor in the File Manager to add these lines in the beginning of the .htaccess file.

RewriteEngine On 

RewriteCond %{HTTPS} off 

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

However, if you wish to force SSL protection only on certain pages, you need to edit the .htaccess file specific to that domain. For more information on how to access the .htaccess, please see the related tutorial

Once you have accessed the .htaccess file inside the file manager take the following steps:

  1. Right-click on the .htaccess file and select the Edit option
  2. Click the Edit button on the pop-up message that appears
  3. At the top of the file- insert the following code

    RewriteEngine On 

    RewriteCond %{HTTPS} off 

    RewriteCond %{REQUEST_URI} /[SSL Requested page]/ 

    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

  1. Click on save changes
  2. Check your website to ensure that it is functioning properly. IN case of any problem, try using the below default cPanel code

   RewriteEngine On 

   RewriteCond %{SERVER_PORT} 80

   RewriteRule ^(.*)$ https://example.com/$1 [R,L]

One thing you need to ensure in this process of SSL redirect htaccess is to replace example.com with your domain name. And do not forget to save changes to redirect HTTP to HTTPs in .htaccess.

Author

Write A Comment