利用.htaccess文件自定义错误页

error利用.htaccess文件可以使你可以拥有个性化的错误页面,这会让你的网站在出错的时候看上去更专业。

任何页面错误代码(例如404找不到页面),都可以通过修改.htaccess文件将其变成自定义页面。

修改方法:ErrorDocument Errornumber / file.html

中文解释:ErrorDocument 错误代码 /目录名/文件名.扩展名

举个例子,如果我的根目录下有一个500mb_404.html文件,我想使用它作为404 error的页面,那么只需要这么写:

ErrorDocument 404 / 500mb_404.html

如果文件不在网站的根目录下,那么你需要这么写:

ErrorDocument 404 /你的路径/500mb_404.html

以下是一些最常用的错误:

常用的客户端请求错误返回代码:

400 – Bad request 错误请求
401 – Authorization Required需要验证
403 – Forbidden禁止
404 – Not Found找不到页面
405 – Method Not Allowed
408 – Request Timed Out
411 – Content Length Required
412 – Precondition Failed
413 – Request Entity Too Long
414 – Request URI Too Long
415 – Unsupported Media Type

常见的服务器错误返回代码:

500 – Internal Server Error 内部服务器错误

剩下的工作就简单了,你需要设计一个错误发生时显示的文件,然后把它们和.htaccess一起上传。

当然,如果所需要提示的信息很少的话,你也可以直接输出提示信息,例如

ErrorDocument 401 “遗憾地告知您:您没有权限访问该页面!”

本文转自:Slyar Home (www.slyar.com)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Captcha Code