How to Redirect your site to SSL using apache and .htaccess

How to Redirect your site to SSL using apache and .htaccess

Chrome and Firefox have started showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to the visitors.  Once you have purchased and installed an SSL certificate, you can configure your server to automatically redirect visitors to the secure version of your website. This ensures data sent to and from your website is securely encrypted. In order to force your web traffic to use HTTPS, you need to edit the codes in the .htaccess file. To do this, please follow the below-given steps:

1) Login to your cPanel account.

2) Navigate to Files >> File Manager.

How to Redirect your site to SSL using apache and .htaccess

 

3) Go to the document root of the domain in which you want to set the https redirection.

How to Redirect your site to SSL using apache and .htaccess

 

4) Click on the Settings menu and make sure that Show Hidden Files (dot files) is checked, and click on the ‘Save’ button.

How to Redirect your site to SSL using apache and .htaccess

 

5) Open your .htaccess file if you already have one. If not, click on the button ‘File+’ on the upper left corner of the page and name the file .htaccess and click the button ‘Create New File’. Please refer the following screenshot for creating a new .htaccess file.

How to Redirect your site to SSL using apache and .htaccess

 

6) Select the .htaccess file, and click ‘Edit’.

How to Redirect your site to SSL using apache and .htaccess

 

7) Paste the following code to your .htaccess file.

RewriteEngine On

RewriteCond %{HTTPS} !=on

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

The above code forces any http request to be rewritten using https. For example, the code forces a request to http://yourdomain.com to load https://yourdomain.com. It also forces directly linked resources (images, css, etc.) to use https.

Please be noted that if you already have “RewriteEngine On” in your existing .htaccess file then you don’t need to duplicate it.

8) Finally, click Save Changes and Close.

That’s all. Visit your website now and you’ll automatically be re-directed to the HTTPS version.

If you need any further help, please do reach our support department.

  • 0

How to Block Bots using Robots.txt File?

How to Block Bots using Robots.txt File? The robots.txt file is a simple text file placed on...

PageSpeed on cPanel Server

PageSpeed on cPanel Server PageSpeed on cPanel Server PageSpeed (mod_pagespeed) is a module for...

How to change cPanel logout URL

How to change cPanel logout URL Do you know that it is possible to change cPanel logout URL any...

How to Change cPanel Style

How to Change cPanel Style How to Change cPanel Style cPanel is the most popular control panel...