404自定义错误模板.htaccess

时间:2012-02-19 19:44:50

标签: .htaccess mod-rewrite redirect rewrite

好的,我有一个问题,我的.htaccess代码是:

RewriteEngine on
ErrorDocument 404 /notfound.html

我在.htaccess附近找不到。

为什么不起作用?我不相信我所看到的。我从这里接受了教程 http://www.htaccessbasics.com/404-custom-error-page/

我只是希望每次访问www.site.com/ajfasoijfiajsfijaofij以显示notfound.html中的内容。

2 个答案:

答案 0 :(得分:2)

使用ErrorDocument时,您指定的文件相对于DOCUMENT ROOT而非.htaccess位置!

修改
假设您有notfound.html并且您想将其用于文件夹dir01,则在此文件夹中创建一个htaccess文件并添加:

ErrorDocument 404    /dir01/notfound.html

如果您想在浏览器中访问您的文件(notfound.html),则为http://www.example.com/dir01/notfound.html。这就是我能解释的全部!

答案 1 :(得分:0)

您可以在.htaccess文件中使用以下代码:

RewriteBase /