To redirect the site from http to https
http - Hypertext Transfer Protocol
https - Hypertext Transfer Protocol over Secure Socket Layer
Most of the sites uses “http” protocol and you can see “http” in the browser’s address bar. But in the e-commerce websites (such as shopping carts) uses payment gateway for online payment. And, those sites uses SSL (secure socket layer) connection to transfer data to and from the payment gateway.
For example, if you type “http://www.gmail.com” in browser after a while the “http” gets converted to “https” in address bar, which means this site is transferring the data over SSL protocol.
To redirect the browser to https when site is using http protocal in PHP
1. SSL must be installed in the server.
2. Function to redirect the browser to “https” in PHP
Function to redirect the browser to “https” in PHP
function redirectToHTTPS()
{
if($_SERVER['HTTPS']!="on")
{
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}
}
you can call the function in Index page to redirect the browser to “https”.
Redirecting whole website to “https” using .htaccess
You can call the above function in all pages to redirect the browser to “https”. Instead of placing the function in every page just write three line of code in .htaccess file to redirect the whole website to use SSL connection throughout the pages.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
0 comments:
Post a Comment