2012-08-01 91 views

回答

4

在你httpd.conf文件,將有一個ErrorDocument部分:

# 
# 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 /missing.html 
#ErrorDocument 404 "/cgi-bin/missing_handler.pl" 
#ErrorDocument 402 http://www.example.com/subscription_info.html 
# 

之後,添加以下代碼:

ErrorDocument 404 /error.html 

這將錯誤頁面設置爲一個名爲error.html文件,它比使用.htaccess文件更好。

2

您可以重定向使用.htaccess文件到您的自定義頁面404個錯誤頁面。

使用HTML/CSS設計您的自定義頁面。一旦你有了404頁面設置,你所需要做的就是將訪問者發送到不正確的URL到這個頁面。要做到這一點就在下面的行添加到您的.htaccess文件:

ErrorDocument 404 /404.php 

你可以任何你想要放置錯誤模板。例如,你可以將所有的錯誤消息被稱爲errormessages

ErrorDocument 404 /errormessages/404.php 

看到這篇文章的文件夾中,How to redirect your 404 error to a custom page

2

這是Apache的一個core feature,並且可以選擇改變404消息的幾種方法。

要使用HTML/CSS創建自己的自定義頁面,這是一種選擇,你可以把你的.htaccess文件:

ErrorDocument 404 /my404.php 
2

在.htaccess中添加

ErrorDocument 404 /path/to/custom/404.php 
0

如果您的服務器上有很多站點託管,並且您希望爲每個站點提供不同的消息,請將.htaccess文件添加到 ErrorDocument 404即可。

如果您希望在所有網站上發生相同的錯誤消息,那麼在httpd.conf中設置ErrorDocument是一種方法。