How to redirect to HTTPS?

0

I'm using CloudFlare and my URLs with HTTPS are already working, but only if I type link if I do not write https, it keeps pointing to http. My hosting is Windows and I was informed by it that I could not use .htaccess to do the redirect because it works only in linux, some suggestions on how to do when accessing the http is automatically redirected to < strong> HTTPS ?

    
asked by anonymous 27.06.2017 / 22:28

2 answers

1

Place the script below into a file that is included by all pages:

if($_SERVER["HTTPS"] == "on")
{
    header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    exit();
}

After this it will do automatic redirect.

But if you wish you can do this by using cloudflare .

    
27.06.2017 / 22:32
1
<?php
function goHTTPS() {
    if ($_SERVER['HTTP'] == "on") {
        $url = $_SERVER['SERVER_NAME'];
        $new_url = "https://" . $url . $_SERVER['REQUEST_URI'];
        header("Location: $new_url");
        exit;
    }
}
goHTTPS();
?>
    
27.06.2017 / 22:33