ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 405 /405.html
ErrorDocument 408 /408.html
ErrorDocument 414 /414.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 504 /504.html
以及一个用于处理任何类型错误的PHP模板,如果您想保持简单。
<?php
$status=$_SERVER['REDIRECT_STATUS'];
$codes=array(
400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
401 => array('401 Login Error', 'It appears that the password and/or user-name you entered was incorrect.'),
403 => array('403 Forbidden', 'Sorry, employees and staff only.'),
404 => array('404 Missing', 'We\'re sorry, but the page you\'re looking for is missing, hiding, or maybe it moved somewhere else and forgot to tell you.'),
405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'),
408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
414 => array('414 URL To Long', 'The URL you entered is longer than the maximum length.'),
500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'),
504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);
$errortitle=$codes[$status][0];
$message=$codes[$status][1];
if($errortitle==false){
$errortitle="Unknown Error";
$message="An unknown error has occurred.";
}
?>
<!doctype html>
<html>
<head>
<title><?php echo("$errortitle");?></title>
<meta charset="utf-8">
</head>
<body>
<!-- Insert headers here. -->
<?php
echo('<h1>'.$errortitle.'</h1>');
echo('<p>'.$message.'</p>');
?>
<!-- Insert footers here. -->
</body>
</html>
错误页面必须是html格式的吗?
不,
任何其他文件扩展名也应该可以。
您可以将文件类型更改为php或任何网页格式。
我知道这篇文章发布已经很久了,但是
我是新手,所以确实有一个问题(=需要帮助)
提到的PHP模板,应该如何使用?
是否需要为每个错误创建一个html文件,然后只需复制粘贴模板中提到的代码行?
感谢任何帮助,提前感谢!
嗨,我将此代码片段用于.htaccess,并创建了错误页面,但由于某种原因,它不起作用。即使我检查了所有文件路径和所有内容,也看不到我的自定义错误页面。
我哪里做错了?
我的htaccess文件如下所示
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?qumatech\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpg|gif|bmp|png)$ /images/dontsteal.gif [L]
请帮忙,我是htaccess新手:/
谢谢!
我遇到了同样的问题。
嗨:D 我遇到了同样的问题,但我解决了它:P 您不能将错误文件放在文件夹中,我将其放在我的站点和htaccess所在的文件夹中,它就起作用了:D 希望我能帮到您:)
这对我的代码来说是一个很棒的补充。
php模板文件应该叫什么名字?
谢谢。
这对我有用
# .htaccesss
# 重定向错误
ErrorDocument 400 /error.php?q=400
ErrorDocument 401 /error.php?q=401
ErrorDocument 403 /error.php?q=403
ErrorDocument 404 /error.php?q=404
ErrorDocument 405 /error.php?q=405
ErrorDocument 408 /error.php?q=408
ErrorDocument 414 /error.php?q=414
ErrorDocument 500 /error.php?q=500
ErrorDocument 502 /error.php?q=502
ErrorDocument 504 /error.php?q=504
我一直在尝试使用此版本以及顶部发布的原始版本,但这两个版本都不起作用。我得到了默认的404错误,但同时还得到了这个
此外,在尝试使用ErrorDocument处理请求时遇到了404未找到错误。
想知道您是否能对此有所启发?也许我只是没有正确实现?我已经在谷歌上搜索过并寻找替代方案,但我找不到像这个一样简单的方案。
是的,在您推荐之前,我确实修复了您版本顶部的错误,它应该写<?php,而不是<?php。
嗨,Andy
我两周前使用了你的代码,发现
如果在URL中放入“[[%&” 比如
http://example.com/%5B%5B%&
然后会出现来自apache的错误页面,而不是来自.htaccess生成的
自定义“ErrorDocument 400 /error.php?q=400” error.php页面以及信息
400错误请求','您的语法不正确。
我该如何解决这个问题?
你好
您的代码在第22行末缺少分号:)
这在我的网站上完美运行。这正是我想要的,因为我不想维护多个错误页面。现在我的错误页面看起来像我的主要页面。
感谢您提供有用的代码
有效且不错。通过在javascript和CSS3上进行少量添加,我能够使其时尚且多语言
查看此内容:http://salim.web.id/error.php
我将回复我自己
阅读有关apache和nginx的内容
无论如何,谢谢
我希望我关于ErrorDocuments的最后一个问题
:-)
上面这个RewriteRule有什么问题?
为什么被阻止的文件/网址没有重定向到生成的404站点,而是我看到了“if($errortitle==false){…”方法???
RewriteRule .* error.php?q=404 [NS,L]
感谢帮助
终于有可用的代码了!^^非常感谢。
在wordpress中将它们放在哪里?
哪个目录和扩展名?
它只是在页面上写/error.php?q=504而不是重定向
酷炫的css
500错误怎么办?对我来说这些不起作用:( Android上的chrome只是显示它自己的500页面而不是显示错误页面。每个400等都工作正常,只有5**不工作