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.

http to https

 

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

http to https

 

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

http to https

 

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.

http to https

 

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

http to https

 

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.

 

Leave A Comment