WordPress.org

Support

Support » Plugins and Hacks » [Plugin: WordPress HTTPS (SSL)] HTTPS when logged in HTTP when not

[Plugin: WordPress HTTPS (SSL)] HTTPS when logged in HTTP when not

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mike Ems

    @mvied

    What are your Site URL and SSL Host? What other settings do you have enabled?

    I’d rather not list the URL at the moment as the site hasn’t gone live yet.

    It’s difficult to know what settings you might need for this. I’ve built a custom theme built on the Roots theme.

    Could you tell me what is supposed to happen with WordPress HTTPS? It looks like it doesn’t do what I want to do out of the box.

    For the time being I’ve created my own work around by adding the following to my functions.php file:

    $https_URL = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     $http_URL  = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    
    if((strpos($_SERVER["REQUEST_URI"],"/login/") !== FALSE OR strpos($_SERVER["REQUEST_URI"],"/contact/") !== FALSE) && $_SERVER["HTTPS"] != "on") {
            header("Location: $https_URL",TRUE,301);
            exit();
    }
    
     // This forces logged in users to use HTTPS
    if (is_user_logged_in() && $_SERVER["HTTPS"] != "on"){
            $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
            header("Location: $https_URL");
            exit();
    }
    
     // Forces not logged in users to use HTTPS (except for certain pages)
    if (!is_user_logged_in() && $_SERVER["HTTPS"] == "on" && strpos($_SERVER["REQUEST_URI"],"/login/") === FALSE && strpos($_SERVER["REQUEST_URI"],"/contact/") === FALSE){
            header("Location: $http_URL",TRUE,301);
            exit();
    }

    It’s a bit of a hack, but it works. I’d far rather use the WordPress HTTPS plugin.

    Thanks!

    Plugin Author Mike Ems

    @mvied

    Force SSL Exclusively does exactly what it describes. Anything not forced to be HTTPS will be redirected to HTTP.

    If your SSL Host does not match your Site URL, it will not be possible to log into both HTTPS and HTTP at the same time. That’s why I asked.

    I’m not sure how the plugin implements redirection- do you rewrite links from http:// to https:// and vice versa? If so, I am wondering whether it is the Roots Theme that is causing the issues. Roots makes all links site relative. This might mean that the HTTPS plugin won’t work.

    Plugin Author Mike Ems

    @mvied

    Impossible to say without looking at it myself, really. It could be anything.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: WordPress HTTPS (SSL)] HTTPS when logged in HTTP when not’ is closed to new replies.