标题(“位置:/”);重定向适用于本地主机,但不适用于远程服务器

tre*_*eng 3 php apache localhost

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

重定向在本地主机上完美运行,但在远程服务器上不起作用。也许使用起来更好$_SERVER?即使我选择与重定向文件位于同一目录中的文件,此重定向也不起作用。希望你能帮助我:)

JJJ*_*JJJ 5

手册中:

\n\n
\n

HTTP/1.1 需要绝对 URI 作为 \xc2\xbb 位置的参数:包括方案、主机名和绝对路径,但某些客户端接受相对 URI。您通常可以使用$_SERVER[\'HTTP_HOST\'],$_SERVER[\'PHP_SELF\']dirname()自己从相对 URI 中创建绝对 URI:

\n
\n\n
<?php\n/* Redirect to a different page in the current directory that was requested */\n$host  = $_SERVER[\'HTTP_HOST\'];\n$uri   = rtrim(dirname($_SERVER[\'PHP_SELF\']), \'/\\\\\');\n$extra = \'mypage.php\';\nheader("Location: http://$host$uri/$extra");\nexit;\n?>\n
Run Code Online (Sandbox Code Playgroud)\n