我正在嘗試為每個錯誤引發一個自定義錯誤頁面
這是我的目錄
.htaccess
error_pages:
error_400.html
error_401.html
error_404.html
uj5u.com熱心網友回復:
你很近。首先,如果您還沒有這樣做,您需要初始化您的 .htaccess 檔案。
RewriteEngine On
接下來,您需要定義錯誤并告訴 .htaccess 用于該錯誤的檔案:
ErrorDocument 400 /error_pages/error_400.html
ErrorDocument 401 /error_pages/error_401.html
ErrorDocument 404 /error_pages/error_404.html
希望這會有所幫助。
uj5u.com熱心網友回復:
您已標記您的問題php,但.html在您的示例中使用?如果您使用的是 PHP,那么您不需要為每個 HTTP 狀態提供單獨的錯誤檔案。您可以使用相同的 PHP 錯誤檔案并檢查REDIRECT_STATUS(即$_SERVER['REDIRECT_STATUS']超全域)以確定觸發錯誤檔案的錯誤狀態。
因此,您的.htaccess檔案將包括:
ErrorDocument 400 /error_pages/error_handler.php
ErrorDocument 401 /error_pages/error_handler.php
ErrorDocument 404 /error_pages/error_handler.php
參考:
- https://httpd.apache.org/docs/2.4/custom-error.html
- https://httpd.apache.org/docs/2.4/mod/core.html#errordocument
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/322376.html
上一篇:域名不重定向
