[英]How to use php header() to redirect to homepage?
我的仪表板页面中有一个链接( dashboad
http://localhost/dashboard.php
)。 链接如下:
<a class="nav-link" href="logout.php">
<img class="icon mb-n1px" src="assets/icons/sign_out.svg" alt="category icon">
Log Out
</a>
在logout.php
文件中,我有以下代码:
<?php
session_unset();
header("Location: /");
exit();
?>
因此,单击该链接,用户代理将重定向到http://localhost/
。 我想重定向到http://localhost
没有斜杠。 我的问题是
header("Location: ");
不行?header("Location: ../");
仍然导致http://localhost/
。header("Location: /../");
不删除尾部斜杠?PS:我已阅读官方文档https://www.php.net/manual/en/function.header.php和其他 SO 帖子,但没有找到任何解释。
您可以使用绝对 url header("Location: http://localhost");
http://localhost
和http://localhost/
是相等的/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.