How to redirect a website from http to https

  Almost a year ago, we migrated Windows Code Bits from http to https. We also published an article showing how to migrate a website to https. That article also explains the importance of https and why every website should use https instead of http. In the present article, we discuss another important thing related to this migration. Here, we shall tell you how to redirect a website from http to https.

  We noticed that even after enabling https on our website, some of our visitors were visiting the http version of this website. This happened because they typed ‘wincodebits.in’ or ‘www.wincodebits.in’ instead of ‘https://www.wincodebits.in’ in the address bar. Some of them clicked a link on another website that contained the http version of the url. To ensure that all of our visitors reach the secured version i.e. ‘https://www.wincodebits.in’ no matter what they type in the address bar, we decided to redirect our website automatically from http to https. How did we do that?

Redirection from http to https

Redirection from http to https

HTTP to HTTPS redirection

  There are several ways to redirect a website from http to https. If the website that needs to be redirected is a WordPress blog, there are two methods that are used most commonly –

  1. Adding some code to .htaccess file
  2. Using a WordPress plugin

  We used the first method because it is fairly easy to implement and is highly reliable. The second method i.e. using a WordPress plugin is also quite easy but it has its own drawbacks. We’ll discuss both methods in detail.

Redirecting http to https by modifying .htaccess file

  To use this method, you need to have access to your website’s cPanel. If, for some reason, you don’t have access to the cPanel you should use the second method.

  1. Login to cPanel and open ‘File Manager’.
  2. Locate the .htaccess file. Please note that it is a hidden file so you must ensure that ‘Show Hidden Files’ option in the Settings/Preferences is checked.
  3. The .htaccess file would be found either in the public_html folder or in yourdomain.com folder.
  4. Once you have located the file, download it and keep it at a safe location in your computer. The .htaccess file is critical to your website. Therefore, you should always keep a backup of this file before making any changes to it.
  5. Now, you have to edit the file. Add the following code to the end of the file and click Save Changes.

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

Ensure that 'Show Hidden Files' is checked

Ensure that ‘Show Hidden Files’ is checked

  Now, it’s time to check whether the method has been successful or not. Type ‘yourdomain.com’ or ‘www.yourdomain.com’ or ‘http://www.yourdomain.com’. In each case, you’ll be redirected to ‘https://www.yourdomain.com’

Redirecting http to https by using a WordPress plugin

  There are some WordPress plugins e.g. Really Simple SSL, Force HTTPS,  that will help you redirect the http links on your WordPress blog to https links. You can use one of these plugins (or other similar plugins) to perform this task quite easily, without getting involved with cPanel and .htaccess. However, there is a drawback to these plugins. These plugins often modify the .htaccess file quite extensively and have their own databases. Due to this, the use of these plugins may cause problems in certain cases. Therefore, we highly recommend using the first method i.e. adding a few lines of code at the end of the .htaccess file. If anything goes wrong (in extremely rare cases), you can easily replace the .htaccess file with the previous version of the file (which you have kept as backup).

  We hope this article helped you understand how to redirect your website’s links from http to https. If this article helped you redirect your own website to https, do share your experience in the comments. Also, if you have any questions/suggestions, tell us in the comments.

(Visited 22 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *