How to Redirect from HTTP to HTTPS

How to redirect from http to https - CodeFlist

Presently, it is important for your website to redirect from HTTP to HTTPS. If the website handles business where they ask login information like bank information, credit, or debit card with the users then https is a must.

While you get the privilege of shopping from home but you should always be careful whether you are entering your sensitive data in the non-secured site. However, there is no need to worry if a website has an SSL certificate and enabled https on their site.

In this post, you will know the advantages of having an SSL certificate. Furthermore, you will learn about redirection.

Why http to https?

Before you move to https, you should have an answer to this.

  • Sensitive Information

As we discussed above if your site handles sensitive information you should enable it. You may never want the payment details of your client to be leaked.

  • Sign of Trust

The green padlock lets the user know that the site is authentic and can be trusted. With this enabled, the users will not receive fake data about the site. Browsers will show the site as insecure in the URL if there is no https. To convert your visitors to customers, you may never want this to happen.

  • Improve Website Speed

It also helps to improve the loading time of the website. Google considers page loading speed as one of the factors that determine the rank of the site. In addition, the visitors will not wait long if your site is slow and not loading within a fraction of second or seconds. You will always find a site with https with an improved speed than the HTTP version.

  • Boost in SEO

Search Engines also give preference for safe sites. When the website operates in https it will be a positive ranking signal for SEO of the site.

  • For better referral data

If your site is running on HTTP and your site is shared on the HTTPS site, the referrer data cannot be tracked. In such a case, the traffic coming from multiple HTTPS sites, displays as direct traffic. In the case of HTTPS to HTTPS propagation, the individual referrer is passed. 

Steps to redirect from HTTP to HTTPS:

Now let’s discuss the real topic. Follow these steps to perform redirection.

  • Backup

Not only redirection but also in every major change it’s safe to have a backup of your site.

  • SSL Certificate

Most of the hosts like SiteGround, Hostgator, etc. provide an SSL certificate for free along with the hosting plan. However, if you have hosted with hosting provider like Godaddy you need to buy an SSL certificate and activate it in your server. Without an SSL certificate, you will never be able to achieve https redirection.

  • Add HTTPS in Admin Area

You need to be sure that whenever you log in to the backend, the information is safely exchanged. In order to perform this operation, Open wp-config.php file and add the code written below before the line “That’s all, stop editing!”

define(‘FORCE_SSL_ADMIN’, true);

As a result, you will be able to login wp-admin with a secure connection.

  • Update Address

Check the site address on the dashboard. Open Settings>General and make sure you have https:// at the beginning of both the WordPress address and site address.

  • Update Links

There can be various links in the database and content in the form of HTTP. You have to change these links to https. In addition, all the external links and templates and function files should be changed to https. During this process, you should check and verify all links including image, video, web fonts, Iframe, Javascript, CSS, etc.

HTTPS Redirection using htaccess in CPanel

Check the root directory. If you have a file named .htaccess you can just edit it else create a plain text file and upload it to the root directory. Perform the following operations to redirect from http to https:

If you have existing code in .htaccess, then add this code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

If you want to redirect a specific domain to use HTTPS, add this code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

However, if you just want to redirect a folder, use this code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$$1 [R,L]

In the code above, you should replace the “folder” with your folder name and “yourdomain” with your domain name.

HTTPS Redirection in Nginx

Firstly, take the backup of the file that you are using for the server directive. Usually, it is present as nginx.conf or default.conf file.

Add this code in that file:

return 301 https://$server_name$request_uri;

Save this file and test the site after you restart the server.

HTTPS Redirection in CDN

If you are using services of CDN like Cloudflare then you will get both a free SSL and always enable HTTPS option under settings. It is located inside the crypto tab in Cloudflare.

HTTPS in Google Search Console and Google Analytics

If your site is running in HTTPS, then you need to add a new property to claim the HTTPS version of your site in Google Search Console. In addition, you need to resubmit a sitemap in the newly added property in GSC. This makes Google easy to understand the structure of your site. This is a compulsory step if you redirect from HTTP to HTTPS.

Furthermore, you may have removed backlinks from your HTTP site by using the disavow file method. In such a case, you need to resubmit this file from the new profile. However, if you do not take this step, Google will miss your disavow file when it’s algorithm is updated.

In a similar fashion, you need to edit site details from HTTP to HTTPS when you in Google Analytics when you redirect the site.

HTTP to HTTPS Redirection Errors

There may be errors in this process that you can easily solve.

  • Mixed Content Warnings

If you have any HTTP links remaining on your web then you will face this error. That’s the reason to perform a site scan for non-secure content. You can use this site in order to find out the reason for mixed content. You can act accordingly.

  • SEO Rankings

You may face a temporary decrease in ranking unless all the link juice is passed when you redirect from HTTP to HTTPS. As a fact, SSL will help your site to rank higher in the long run.

Wrapping Up

Hopefully, now you can redirect from HTTP to HTTPS. In addition, the post gives a general concept about the importance of SSL and HTTPS in improving the performance, speed, and SEO of the site.

Additional Readings