首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP头404 .htaccess ErrorDocument在本地机器上不工作(MAMP)

问PHP头404 .htaccess ErrorDocument在本地机器上不工作(MAMP)
EN

Stack Overflow用户
提问于 2014-09-12 01:35:47
回答 1查看 1.8K关注 0票数 3

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

下面是我的index.php的内容:

代码语言:javascript
复制
<?
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:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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但没有重定向。

从我的阅读来看,所有这些结合在一起应该会起到作用;似乎仍然遗漏了一些东西。

EN

回答 1

Stack Overflow用户

发布于 2014-09-12 02:02:29

您在此处使用ErrorDocument是错误的:

代码语言:javascript
复制
ErrorDocument 404 /Users/me/folder/mamp/404.php

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

代码语言:javascript
复制
ErrorDocument 404 /404.php

或

代码语言:javascript
复制
ErrorDocument 404 http://domain.com/404.php
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25793755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档