ITeye博客

设置apache错误转向(500,404,401,403)

iammonster · 2009-08-11 14:09 · apache-tomcat · Markdown

一、很重要:

官方文档在这里:http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

 

二、稍微说下:

 

1、语法:

ErrorDocument error-code  document 

 

2、可以设置的地方:server config, virtual host, directory, .htaccess

 

3、有四种处理方式:

   (1). 输出一个简单生硬的错误代码信息
   (2). 输出一个定制的信息
   (3). 重定向到一个本地的URL-path
   (4). 重定向到一个外部的URL

 

三、实例设置如下 :

 

1、定制处理机制:

ErrorDocument 500 http://foo.example.com/cgi-bin/tester
ErrorDocument 404 /cgi-bin/bad_urls.pl
ErrorDocument 401 /subscription_info.html
ErrorDocument 403 "Sorry can't allow you access today" 

 

 2、某个特定地方(如:/web/docs)取消(父上下文)设置的处理方式(2-4),回到默认处理方式1,则:

ErrorDocument 404 /cgi-bin/bad_urls.pl

<Directory /web/docs>
ErrorDocument 404 default
</Directory> 

 

四、我的应用是在虚拟主机中加个404错误的重定向 ,如下:

<VirtualHost *:80>
//……

ErrorDocument 404 http://jiemeng.baobeil.com/index2.html

</VirtualHost>

现在访问 www.baobeil.com/life/yinshi.htm 则会转向到  http://jiemeng.baobeil.com/index2.html

 

五、其他注意事项请参考:一、很重要

评论(1)

  1. #1 楼 · lucky16 · 2009-08-12 12:12

    学习了,受教了!

评论功能维护中,当前仅展示历史评论。