apache 自定義404錯誤頁面


1.有些提供web服務的網站,在用戶訪問一個不存在的網站文件時,會提示404錯誤,如下所示:

現在要求自定義一個錯誤頁面,也就是出現404錯誤代碼時,跳轉到我們自定義的網址上。下面記錄下方法:

  • 1.編輯httpd.conf
    vim /etc/httpd/conf/httpd.conf
    # Customizable error responses come in three flavors:
    # 1) plain text 2) local redirects 3) external redirects
    #
    # Some examples:
    #ErrorDocument 500 "The server made a boo boo."
    #ErrorDocument 404 /404.html
    #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
    #ErrorDocument 402 http://www.example.com/subscription_info.html
    #

    找到以上文件,將404那一行注釋去掉。去掉之后,在網站根目錄下/var/www/html/新建一個錯誤頁面404.html(這里可以修改其它名字,但httpd.conf中也要保持一致),創建后,編輯一下,輸入this is test page文字。然后,重啟apache

    # service httpd restart

     

    最后,測試一下網站。跳轉到錯誤頁面了。


免責聲明!

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



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