How to redirect your website from HTTP to HTTPS

3 ways to redirect website from http tp https

Before this you will be sure that SSL installed in server

if not you can install ssl free also , Read instruction carefully . searc google free ssl provider.

1.  By php function


<?php
function redirectTohttps() {
if($_SERVER[‘HTTPS’]!=”on”) {
$redirect= “https://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
header(“Location:$redirect”);
}}
?>

2.  By meta tag

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

simply add this line into header





3. htaccess method


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

Comments