3 Simple Ways To Redirect a Website From Http to Https

The most important part in hosting a website online is to look for its security because nowadays malicious activities have increased from 45% on the servers with no security protocols. SSL can be a good option over it, but beware of open source SSL which is free, but at the same time not secure to protect a site because of its open code and Heratbleed is one example of it. The Hypertext Transfer Protocol (HTTP) is an application protocol used for distributed, collaborative, multimedia data systems. The “S” in https stands for “Secure Socket Layer” (SSL).

Why SSL? Why do I need SSL? What will it do for me? This is an important question for all websites and for everyone involved in the web. SSL(secure sockets layer) is the backbone of our secure Internet and it protects sensitive information on a website. It creates a secure connection between a customer’s web browser and the server of the company they’re interacting with. There are many benefits to switching to an https site, however many peoples concerns that it will hurt their search rankings, damage their SEO efforts. After a research on SSL and not SSL based website Google has come up with a solution for all- “Websites with HTTPS can perform really well on search engines to improve ranking,” says Matt Cutts of Google.

Let’s take a look at the 3 Simple Ways To Redirect a Website From Http to Https,

Method:1- .htaccess file

You can use this code and edit .htaccess file to move from Http to Https,

Please add this to the .htaccess file

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

 Generally websites use the http protocol as a default protocol to handle all the information, but Https can be a secure way to run a website online.

How it Works?

The three commands: RewriteEngine, RewriteCond and RewriteRule.

The “RewriteEngine On” tells Apache we are going to use mod_rewrite. The “RewriteCond % {HTTPS}” off, to check if the https protocol is active or not, and If the https protocol is used then the last line (RewriteRule) will not apply. The last line “RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}” tell the server to only rewrite the first part (http://) to (https://).

Method:2 – Using php Function

You can use the following php function to redirect your website using php code. You just have to call the function in the page at appropriate place where you need the redirect from http to https.

< ?php

function redirectTohttps() {

if($_SERVER[‘HTTPS’]!=”on”) {

$redirect= “https://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

header(“Location:$redirect”); } }

?>

How it Works?

Please check first that SSL is installed on the server. Now to redirect the browser to “https” , You must know that the site is using SSL or not at the moment. And for this, there is a defined server variable in PHP called “HTTPS”. $_SERVER[‘HTTPS’] returns “on” values when the site is using an SSL connection.

 Method :3 – HTML Meta Tag

Above two methods are enough to make a move from Http to Https, in comparison this method is not the most perfect one, but you can use it if you are not able to use the “mod rewrite”.

Please add the following code to your web page header,

< meta http-equiv=”Refresh” content=”0;URL=https://www.yourdomainname.com” />

How it Works?

Please make sure the site with SSL encryption is listening only on port 443 for the IP address you’ve assigned. Now create a separate website using similar IP address, which pay attention to port 80. Create a single file at the root level and call it as default.htm or default.asp. Use meta refresh tag, if you want to use HTML.

Be Sociable, Share!