Add Forfully Redirect http to https using php code without .htaccess
This tutorial is for redirecting the http URL to https using the PHP code if your .htaccess will not work for the SSL. It will just redirect all your HTTP URLs to HTTPS without using the .htaccess if your server HTTPS is not on. Just follow the step, and you can get your own redirection.
Step 1)
Just put this code in your main root file or connection file, which is included everywhere inyour project. So every time a URL is scanned with this code, if it finds the http, it will convert it into https.
if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' ||
$_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
{
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
Saved as a favorite, I really like your web site!
I am sure this piece of writing has touched all the internet viewers, its really really nice article on building up new weblog.
Ahaa, its nice discussion regarding this piece of writing at this place at this blog, I have read all that, so at this time me also commenting at this place.
Hola! I’ve been reading your blog for some time now and finally got the bravery to go ahead and give you a shout out from Dallas Tx! Just wanted to tell you keep up the excellent work!
What’s up, I check your blogs regularly. Your humoristic style is witty, keep up the good work!