Redirect http to https SSL

You will have noticed that some website URLs commence with http, while others start with https. Each of these is a protocol that is used every time you access the internet from a browser.

https – the S standing for ‘secure’ – provides a more secure environment from which to access the web, making use of a technology called SSL encryption. Data is completely scrambled as it is sent from one online server to another.

In this guide we outline everything you need to know about how to redirect http to https.

Find out some useful basic information about SSL and https in the short video below. If you have one of our website management packages, get in touch and we can help you directly.

Google has recently stressed the importance of providing an encrypted SSL connection as a factor in its complex ranking algorithm.

As Google starts this transition, we will see sites that have not secured an SSL certificate start to lose search engine rank as a result. For this reason, it is essential that you ensure your web site is protected.

When you do get an SSL certificate for the first time, you will need to update your URL settings as required to keep all links working as expected. The prefix of all your URLs will change from http to https, and it’s essential to put the proper redirections in place to prevent any broken links, and to ensure visitors always land on the secure, https version of your website.

https redirection

Redirecting all web pages to https

There are a number of ways you can configure your site to redirect all http URLs to https. Two of the most commonly used are

  • Using the .htaccess file
  • Using PHP

We are going to show you how to set up redirections using these methods, and which is the preferred method.

1.  Redirect all pages to https using .htaccess

The easiest way to redirect all URLs to https is by using the htaccess file. Access this by either using the file manager in cPanel or using FTP software such as FileZilla. We recommend using FTP for a more streamlined process.

Open up the htaccess file using a program of your choosing. If you are using file manager in cpanel, you will be able to access directly from your browser. If you are planning on editting the file on your computer, use any text or code editor, such as notepad or Sublime Text

Press enter a few times to create a few blank lines at the top of the file. Copy and paste the following lines of code:

#Redirection code starts

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

#Redirection code Ends

You do not need to edit the code after pasting it into your htaccess file.

Adding redirect code to htaccessfile

Explanation

We have included three commands in the code above: ReWriteEngine, ReWriteCond and ReWriteRule.

We’ve described what each of them does below.

ReWriteEngine On This tells Apache we are using the mod-rewrite command.
 ReWriteCond %{HTTPS} off This checks if the protocol https is already in use. If the condition is true (not using https), the below rule applies.
 ReWriteRule^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] This tells the server to rewrite only http to https.

Now, when you access any page on your website, it should revert to the secure https version by default.

2.  Redirecting to https using PHP

It is also possible to redirect your website pages to the SSL version using php. However, this method comes with the drawback that the php code must be present on every page that you want to redirect. For this reason, we recommend the htaccess method for site-wide redirections.

In case you do want to use the php method, here’s the code:

Copy to Clipboard

You should also know that SSL must be installed on the server in order for this to work.

I hope this guide provided all the information you need on how to redirect http to https. Let us know how you get on in the comments. If you need more assistance, feel free to get in touch and one of our developers can help you out.

Need more traffic and leads?

Get a free website review.