Redirect HTTP to HTTPS Using .htaccess File

Modern web browsers like Google Chrome and Firefox started to show a website visitor insecure warnings on sites without SSL certificates. If your website is not running on HTTPS or does not have an SSL certificate, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reasons is necessary. It becomes very important to redirect from HTTP to HTTPS.

This article will explain how to redirect your website's visitors from HTTP to HTTPS. You need to have an SSL certificate installed on your hosting account or server in order for this method to remove the insecure warning from the visitor's browser while on your website.

First you need to create a .htaccess file if it does not exist or modify an existing file on your server or hosting account.

 

 

Choose one of the following ways to create/edit a .htaccess file

  • Create/Edit the htaccess file on your computer and upload it to the server or hosting account using FTP.
  • Browse your public html directory using an FTP program and create or edit the htaccess file directly using an FTP program that supports direct editing.
  • Create/Edit the htaccess file on your computer and upload it to the server using SSH or directly create and edit the file on your server using your favourite Linux text editor.
  • Using the file manager on your server's control panel, browser for the public html directory and create or edit the htaccess file directly or create / edit it on your computer and upload it.

 

 

Before making any modifications to an existing htaccess file, be sure to make a back of of the file before editing. You can easily backup the htaccess file by opening it using a text editor and copy past the content to another file or make a copy of the file and name it htaccess_backup for example.

 


Redirecting all web traffic from HTTP to HTTPS

Copy the following code and paste it in your htaccess file

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

 

 

Last update: December 4th, 2018

  • htaccess, HTTPS, Redirect
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How to enable Elastic skin for Roundcube 1.4?

Description: Roundcube 1.4 has been released with a new responsive skin. Elastic is the first...

How to find the server IP address

There are many cases where you need to find the IP address of the server hosting your website.-...

How to Create an FTP Account in cPanel

FTP is no longer supported due to security issues. We only allow SFTP, follow the following link...

How to SFTP to a server with a private key

This article will explain how to connect to a server using your private key over sftp in order to...

Domain has exceeded the max defers and failures per hour

This article will explain why you would receive a notification like "Domain has exceeded the...