apache定制错误页面

编辑配置文件,错误页面定制支持三种形式:

1. 普通文本

2. 本地跳转

3. 外部跳转

复制代码
[root@ken-node2 ~]# vim /etc/httpd/conf/httpd.conf
...
327 #
328 # Customizable error responses come in three flavors:
329 # 1) plain text 2) local redirects 3) external redirects
330 #
331 # Some examples:
332 #ErrorDocument 500 "The server made a boo boo."
333 #ErrorDocument 404 /missing.html
334 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
335 #ErrorDocument 402 http://www.example.com/subscription_info.html
...
复制代码

普通文本

第一步:取消332行处的注释,如果404错误就会输出后面的一句话至页面

复制代码
327 #
328 # Customizable error responses come in three flavors:
329 # 1) plain text 2) local redirects 3) external redirects
330 #
331 # Some examples:
332 ErrorDocument 404 "The server made a boo boo."
333 #ErrorDocument 404 /missing.html
334 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
335 #ErrorDocument 402 http://www.example.com/subscription_info.html
复制代码

第二步:修改完之后重启apache

[root@ken-node2 ~]# systemctl restart httpd

第三步:浏览器访问一个不存在的内容

本地跳转

第一步:编辑httpd配置文件

复制代码
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 404 "The server made a boo boo."
ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
复制代码

第二步:编写错误页面

[root@ken-node2 html]# echo "this is missing page" > missing.html
[root@ken-node2 html]# ls
missing.html

第三步:重启httpd

[root@ken-node2 html]# systemctl restart httpd

第四步:浏览器测试

外部跳转

第一步: 编辑httpd配置文件

复制代码
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 404 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
ErrorDocument 404 https://www.cnblogs.com/daisyyang/   #取消该行注释,后面跟上我的外部博客网址
#
复制代码

第二步:重启httpd

[root@ken-node2 html]# systemctl restart httpd

第三步:浏览器访问

这个时候输入错误页面会直接跳转到我的博客

原文地址:https://www.cnblogs.com/daisyyang/p/11112275.html