我想知道是否有人以前见过这个问题,你是否有解决它的答案。基本上,我有一个页面是SSL加密的,还有一些页面没有/不能加密(由于依赖插件)。所以在没有SSL的页面上,我检测到一个标头,并尝试重定向到页面的HTTP版本:
if($_SERVER["HTTPS"] == "on")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com");
exit();
}
然而,PHP似乎阻止了我从安全域重定向到同一域的非安全站点!
如果我从https://www.example.com -> http://www.secondsite.com
开始,它会起作用,但https://www.example.com -> http://www.example.com
迫使我留在加密的网站上,并导致无休止的重定向。
有什么线索吗??
Ric
您可以确保您的标头尚未发送,这可能是保持在同一页面上的情况。参见php手册:
function redirect($url, $debug=FALSE){
// If headers not sent yet... then do php redirect
if (!headers_sent()) {
header('Location: '.$url);
exit;
// if headers are already sent... do javascript redirect... if javascript is disabled, do html redirect.
} else {
// Js redirect
echo '<script type="text/javascript">';
echo "<!--";
echo 'window.location.href="'. $url .'";';
echo "//-->";
echo '</script>';
// HTML redirect if js disabled
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>';
}
}//==== End -- Redirect