gpt4 book ai didi

PHP header 404 .htaccess ErrorDocument 在本地计算机 (MAMP) 上不工作

转载 作者:行者123 更新时间:2023-12-04 18:06:20 25 4
gpt4 key购买 nike

目前我收到 404 错误,但它不会重定向到 404.php

这是我的 index.php 的内容:

<?
header("HTTP/1.1 404 Not Found");
exit;
?>
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Index</h1>
<p>This is the homepage, but I'd like it to go to 404.php!</p>
</body>
</html>

这是 404.php:

<html>
<head>
<title>404</title>
</head>
<body>
<h1>Page Not Found!</h1>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
<p>This is my test custom 404 page!</p>
</body>
</html>

这是.htaccess:

ErrorDocument 404 /Users/me/folder/mamp/404.php

/Users/me/folder/mamp/404.php 表示 MAMP 首选项中的根文档文件夹。

我也试过.htaccess中/404.php的相对路径和http://localhost:8888/404.php的URL。到目前为止所有相同的结果,一个白页,发出 404 但没有重定向。

根据我的阅读,所有这些结合起来应该可以解决问题;似乎仍然缺少一些东西。

最佳答案

您对 ErrorDocument 的使用在这里是错误的:

ErrorDocument 404 /Users/me/folder/mamp/404.php

您需要使用 DocumentRoot 的相对路径或使用以 http 开头的完整 URL。所以使用:

ErrorDocument 404 /404.php

ErrorDocument 404 http://domain.com/404.php

关于PHP header 404 .htaccess ErrorDocument 在本地计算机 (MAMP) 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25793755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com