3 Simple Ways To Redirect a Website From Http to Https
The major part in hosting an web site on-line is to look for its security as a result nowadays malicious activities have increased from 45% on the servers with no security protocols. SSL is a decent choice over it, however beware of open source SSL that is free, but at constant time not secure to shield a web site. The Hypertext Transfer Protocol (HTTP) is an application protocol that is used for distributed, collaborative, multimedia data systems. The “S” in https indicated as “Secure Socket Layer” (SSL).
Why SSL? Why do i required SSL? what’s going to it do for me? This is often a vital question for all web sites and for everybody concerned within the web. SSL(secure sockets layer) is that the backbone of our secure web and it protects sensitive data on a web site. It creates a secure connection between athe server of the company they’re interacting with and with the customer’s web browser. There are several benefits to shift to an https web site, but several peoples issues that it’ll hurt their search rankings, harm their SEO efforts. After a research on SSL and not SSL based mostly web site Google has come up with an answer for all- “Websites with HTTPS can perform actually well on search engines to enhance 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.