How to Redirect HTTP to HTTPS

Redirecting HTTP to HTTPS is a necessary thing once you migrated your website to the SSL version. Otherwise, your website will serve two versions of the same content in the form of a non-HTTP page and an HTTPS page. For example, if you setup the SSL certificate on your website and if your web hosting provider doesn’t have the automatic redirection option, you will not redirect the HTTP visitors to the HTTPS. Luckily, most of the known web hosting services such as Siteground will automatically redirect you to the SSL version once you use the Let’s Encrypt free SSL from their CPanel.

However, after installing the SSL, make sure that your HTTP website is properly redirecting every page to the HTTPS version. If not, just follow this guide to do so.

Redirect HTTP to HTTPS

While redirecting, there may be few variation of the software and systems. So, follow the steps under the correct one.

Never save your .httaccess or other mentioned files without confirming the code is correct. Even a single incorrect word could result in a website crash. But it can be reversed by deleting the added code. Always be cautious and rake a backup of the files before editing.

Linux & cPanel

Add the following code to your .httaccess file to redirect visitors from HTTP to HTTPS.

Make sure that all the opening tags closed properly and never repeat the existing tags in your web.config file. It means, if already there is a <configuration> tag, you shouldn’t repeat it and should place the remaining code inside that tag resulting in the above structure.

Apache

Apache HTTPS redirection can be done both using the .httaccess file and the httpd.conf file. We already discussed the .htaccess method. So, we are now looking into editing the httpd.conf file.

Go to the conf folder of your Apache server and add the following code to the httpd.conf file.

That’s it, make sure that the server is redirecting your website to HTTPS.

WordPress

Instead of spending time on the above given complicated SSL redirection codes, you could easily do the same by installing a WordPress plugin. We are going to use the Simple SSL Plugin available in the WordPress repository. You will be also able to install SSL certificates using this plugin. Download and install the plugin on your WordPress site, install SSL certificate if you don’t already installed. The plugin will automatically redirect your HTTP traffic to the HTTPS version. If not, check the configuration of the plugin.

Joomla

To configure HTTPS redirection in Joomla, there are two phases you have to follow. They are given below. Make sure to complete the phase 1 before stepping into the phase 2.

Phase 1: configuring configuration.php file

Open the configuration.php file

Replace the line var $live_site =”; with var $live_site = ‘https://www.example.com’; (Only if not already done.)

Now, open the .htaccess file then add the following code at the bottom.

Things to remember while redirecting HTTP to HTTPS

There are few things that you should be aware of before applying the HTTPS redirection on your website. We listed some of the below.

You should use the 301 permanent redirection while redirecting your website. Never use any other temporary redirection. It may result in the loss of the backlink juice which links to the HTTP version of your website. The 301 redirect directly passes the link juice without significant loss.

Don’t take redirection measures before confirming that all of your website pages are accessible from the HTTPS version too.

After applying the redirection, make sure that the site is not accessible from the HTTP version. In other words, if we enter http://example.com to the browser, it should take you to https://example.com.

Never save the code without double-checking everything is correctly entered.