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

 

第三步:瀏覽器訪問

這個時候輸入錯誤頁面會直接跳轉到我的博客

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM