• I have a form in wordpress where the form action = swagHome.php. In that file I try to redirect with:

    header(“Location: https://www.sustainablewestonma.org/”);

    but it’s not working. I definitely get to that line of code but nothing happens.

    I also tried wp_redirect() but that doesn’t seem to work either.

    • This topic was modified 6 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Thread Starter rssail

    (@rssail)

    I adapted the following from CS50 and it works

    function redirect($destination){
    // handle URL
    if (preg_match(“/^https?:\/\//”, $destination)){
    header(“Location: ” . $destination);
    }else if (preg_match(“/^\//”, $destination)){
    // handle absolute path
    $protocol = (isset($_SERVER[“HTTPS”])) ? “https” : “http”;
    $host = $_SERVER[“HTTP_HOST”];
    header(“Location: $protocol://$host$destination”);`
    }else if (preg_match(“/^www/”,$destination)){
    //handle www addresses (added by rss)
    $protocol = (isset($_SERVER[“HTTPS”])) ? “https” : “http”;
    header(“Location: $protocol://$destination”);
    }else{
    // handle relative path
    // adapted from http://www.php.net/header
    $protocol = (isset($_SERVER[“HTTPS”])) ? “https” : “http”;
    $host = $_SERVER[“HTTP_HOST”];
    $path = rtrim(dirname($_SERVER[“PHP_SELF”]), “/\\”);
    header(“Location: $protocol://$host$path/$destination”);

    }

    // exit immediately since we’re redirecting anyway
    /****************
    print($_SERVER[“HTTPS”].'<br>’);
    print($_SERVER[“HTTP_HOST”].'<br>’);
    print($host.'<br>’);
    print($path.'<br>’);
    print($destination.'<br>’);
    print_r2($_SERVER);
    *****************/
    exit;
    }

    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
    • This reply was modified 6 years, 5 months ago by rssail.
Viewing 1 replies (of 1 total)

The topic ‘redirect not working’ is closed to new replies.