php – header(“Location:/”); redirect适用于localhost,但不适用于远程服务器

if (condition)
{
#lol. Some code here
}
else
{       
header("Location:/");//i'm trying to redirect to the root
}

重定向在localhost上完美运行,但在远程服务器上运行不正常.
使用$_SERVER可能更好吗?
即使我选择与具有重定向文件位于同一目录中的文件,此重定向也不起作用.
希望你帮帮我:)

manual

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme,hostname and absolute path,but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'],$_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

<?PHP
/* Redirect to a different page in the current directory that was requested */
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
$extra = 'mypage.PHP';
header("Location: http://$host$uri/$extra");
exit;
?>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...