https redirection using the functions.php of a theme

  • Unknown's avatar

    i have installed ssl certificate on my site now i want to force the ssl on certain pages
    i have tried many options using the ht-access file but failed; finally, i succeeded using the theme’s function.php but the code i added forces ssl or https for a single page(page id= 149) and http on all other now i want to modify the code to force https on 2 to 3 pages (say page id = 150 and 167) of my requirement and force http on the rest here’s the code …pls help me….

    function force_ssl()
    {
    // Specify ID of page to be viewed on SSL connection
    if (is_page(149) && !is_ssl () )
    {
    header(‘HTTP/1.1 301 Moved Permanently’);
    header(“Location: https://” . $_SERVER[“SERVER_NAME”] . $_SERVER[“REQUEST_URI”]);
    exit();
    }
    // All other pages must not be https
    else if (!is_page(149) && is_ssl() )
    {
    header(‘Location: http://’ . $_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’]);
    exit();
    }

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    i have installed ssl certificate on my site now i want to force the ssl on certain pages
    i have tried many options using the ht-access file but failed; finally, i succeeded using the theme’s function.php but the code i added forces ssl or https for a single page(page id= 149) and http on all other now i want to modify the code to force https on 2 to 3 pages (say page id = 150 and 167) of my requirement and force http on the rest here’s the code …pls help me….

    function force_ssl()
    {
    // Specify ID of page to be viewed on SSL connection
    if (is_page(149) && !is_ssl () )
    {
    header(‘HTTP/1.1 301 Moved Permanently’);
    header(“Location: https://” . $_SERVER[“SERVER_NAME”] . $_SERVER[“REQUEST_URI”]);
    exit();
    }
    // All other pages must not be https
    else if (!is_page(149) && is_ssl() )
    {
    header(‘Location: http://’ . $_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’]);
    exit();
    }

  • Unknown's avatar
  • The topic ‘https redirection using the functions.php of a theme’ is closed to new replies.