1

I have my site configured through .htaccess to do this:

ErrorDocument 403 http://www.mydomain.com/error.php?e=403
ErrorDocument 401 http://www.mydomain.com/error.php?e=401
ErrorDocument 400 http://www.mydomain.com/error.php?e=400
ErrorDocument 500 http://www.mydomain.com/error.php?e=500

error.php logs the error and shows a user/customer friendly error page.

Also, I've added this piece of code:

if($_GET['e'] == '404' || $_GET['e'] == '403' || $_GET['e'] == '500' )
{   $error_no = $_GET['e']; } else { $error_no = '200'; }
header(' ', true, $error_code);

So when I visit mydomain.com/pagedoesnotexist I see the error page (but the address bar still shows the non existing URL), I receive a report that a 404 page was triggers, but I took a look at my server log file, and this is what it says: MY.IP.000.00 - - [date and time] "GET /pagedoesnotexistHTTP/1.1" 200 2450 "-" "USERAGENTINFO"

Nowhere in my server log can I see anything about 404... only 200... Why is that? How can I make it send back a 404 code? Right now I assume that bots and such always get 200, meaning OK responses when visiting non existent sites... Or am I missing something?

*and off topic: what does 2450 stand for? O_o*

4

1 回答 1

1

但是请注意,您设置ErrorDocument不正确,这会导致外部重定向并返回您200而不是404403。将您的设置ErrorDocument如下,不带域名

ErrorDocument 403 /error.php?e=403
ErrorDocument 401 /error.php?e=401
ErrorDocument 400 /error.php?e=400
ErrorDocument 500 /error.php?e=500

这将在您的浏览器中保留原始未找到的 URL,同时返回正确的 HTTP 状态代码。

关于您的代码:

您正在设置变量$error_no$error_codeheader()函数中使用。你应该使用:

if($_GET['e'] == '404' || $_GET['e'] == '403' || $_GET['e'] == '500' )
{   $error_no = $_GET['e']; } else { $error_no = '200'; }
header(' ', true, $error_no);
于 2013-09-22T05:55:47.810 回答