【发布时间】:2018-01-03 12:13:29
【问题描述】:
我想使用本地 URL(相对路径)来显示我的自定义 404 错误消息,但它似乎没有按预期工作。正如 apache 文档所述 here :
ErrorDocument 指令的语法是:
ErrorDocument <3-digit-code> <action>操作将被视为:
要重定向到的本地 URL(如果操作以“/”开头)。
要重定向到的外部 URL(如果操作是有效的 URL)。
要显示的文本(如果以上都不是)。如果文本包含多个单词,则文本必须用引号 (") 括起来。
方法 2 和 3 工作正常。出于测试目的,想象一个名为 test 的文件夹,其中包含 3 个文件。
index.php: 主页
404.php:自定义 404 页面
.htaccess:
RewriteEngine On
ErrorDocument 404 /404.php
现在访问此 URL http://localhost/test/blah-blah 不会显示我的 404.php 页面,而是显示默认的 Not Found 页面并显示此消息:
The requested URL /tests/test-htaccess/asdasd was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
知道如何解决这个问题吗?
【问题讨论】:
标签: apache .htaccess mod-rewrite