ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

apache定制错误页面

2019-07-01 09:41:00  阅读:213  来源: 互联网

标签:httpd redirects ErrorDocument missing html 404 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

 

第三步:浏览器访问

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

 

标签:httpd,redirects,ErrorDocument,missing,html,404,apache,定制,页面
来源: https://www.cnblogs.com/daisyyang/p/11112275.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有