自訂 Apache 404 頁面

自訂 Apache 404 頁面

我想將 Ubuntu 上的 Apache Web 伺服器的 404 頁面自訂為常規頁面以外的頁面:

Not Found

The requested URL /***** was not found on this server.
______________________________________________________

Apache/*.*.** (Ubuntu) Server at **** Port 80

如何才能做到這一點?

答案1

我自己找到了答案。

您必須編輯檔案 /etc/apache2/conf.d/localized-error-pages

sudoedit /etc/apache2/conf.d/localized-error-pages

您可以輸入純文字或腳本或 html 的鏈接

答案2

<VirtualHost 192.168.0.1:80>
    ServerAdmin [email protected]
    ServerName host.ru
    ServerAlias www.host.ru
    DocumentRoot /home/WebServer/www/host.ru/public_html/
    ErrorLog /home/WebServer/www/host.ru/logs/error.log
    CustomLog /home/WebServer/www/hostu/logs/access.log combined


    Alias /error_html/ "/home/WebServer/www/host/error_html/"
    <Directory "/home/WebServer/www/host.ru/error_html">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en cs de es fr it nl sv pt-br ro
        ForceLanguagePriority Prefer Fallback
    </Directory>
    ErrorDocument 404 /error_html/HTTP_NOT_FOUND.html
</VirtualHost>

答案3

這是一個解決方案。希望能幫助你。

示範版

前往您網站的資料夾。

建立一個名為.htaccess(只是.htaccess沒有名稱,只有檔案副檔名)。

打開文件並添加該行。

錯誤文檔 404/檔案路徑

代替/檔案路徑使用您的 404 頁面檔案名,該檔案應位於與該檔案相同的資料夾中.htaccess。習俗404文件可以是 PHP 或 HTML。您也可以像這樣新增 HTML:

錯誤文檔 404 '<h1>404 找不到</h1>'

您不必重新載入 Apache 伺服器!都結束了。測試一下。

來源 -蘇斌的博客

答案4

AFAIK 您無法以任何簡單的方式自訂 Apache 2.4 的預設錯誤訊息,因為這些訊息位於apache2執行檔內。

但是,您可以使用“ErrorDocument”指令覆蓋它們,該指令也可以在apache2.conf.

一種更好的方法是使用Includeinapache2.conf並在一個單獨的檔案中收集覆蓋的訊息。

另請參閱Apache 2.4 文件

相關內容