[英]404 error page showing HTTP Status 200 instead of 404
我有以下用於執行重定向的代碼。 如果我的$includeFile
不存在,它將重定向到404頁面。 這是我的index.php
的片段
if ( !file_exists($includeFile) )
Header( "HTTP/1.1 404 Page Not Found" );
Header( "Location: http://legascy.com/404_error/");
但是http://legascy.com/404_error/
顯示的是HTTP狀態200,而不是404。
如何解決呢?
您需要將404的標頭函數放在“ 404_error”頁面上,而不是重定向頁面上。 這是因為瀏覽器被發送到404_error,它具有默認的200狀態代碼。
if ( !file_exists($includeFile) ) {
header("Location: http://legascy.com/404_error/");
}
並在404_error / index.php上:
header("HTTP/1.1 404 Page Not Found");
您之前發送404錯誤代碼的標頭已被Location標頭丟棄,瀏覽器將用戶帶到新頁面。 重定向到的頁面可用,因此它將始終顯示200。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.