Forum Moderators: phranque

Message Too Old, No Replies

http status after redirect

http error php header location script

         

olaf

9:52 am on Nov 21, 2005 (gmt 0)

10+ Year Member



Hello,

I'm using a customized error script together with

this few lines in .htaccess file:
ErrorDocument 400 /error.php?err=400
ErrorDocument 401 /error.php?err=401
ErrorDocument 403 /error.php?err=403
ErrorDocument 404 /error.php?err=404
ErrorDocument 500 /error.php?err=500

inside the error.php there is a mailfunction (and some filters) and at last this code:

header("HTTP/1.1 ".$error." ".$http_msgs[$error]);
header("Location: ".$redirect_to);

so, first I send the http error back and then I redirect to a part. page (home).

If I check the status for a not existing file than it's a 302. My question is, if google spiders my website, does the crawler get a 404 error?

kind regards
Olaf

jdMorgan

4:03 pm on Nov 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, the crawler sees a 302, just like the header checker does. As evidenced by all the recent '302 hijacking' threads here on WebmasterWorld, that can confuse 'bots and cause serious problems with your page rankings in the SERPs.

You should remove the "Location:" header from the code for the 404 response. If you wish to redirect the visitor, then this should be done by the /error.php?err=404 script *after* the 404 response.

Jim

olaf

7:56 pm on Nov 21, 2005 (gmt 0)

10+ Year Member



then this should be done by the /error.php?err=404 script *after* the 404 response.

What do you mean exactly with this? the 404 error is provided by the server and the I send a header with a 404 error and then the redirect is done.

Of course I ask this to do it right for Google ;-)

I tested in the meantime a little bit with this code:


<?php
$fp = fsockopen("www.pefina.nl", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /sdfsdf.htm HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>

(this script "test.php" is live at the moment)

If I run this script I get an 404 error... :-S

gr. Olaf

jdMorgan

2:57 am on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I got confused as to which page (script) was doing what. If your server responds with a 404, and the custom 404 page then invokes a redirect, then the HTTP protocol requirements are satisfied.

It is imporatant to use a testing method that will show you the handhake between the client and the server one step at time. So the server header checker (they typically don't follow redirects) will show you the 404, and only if you then 'follow' the redirect on that 404 error page will the server header checker show you the 302.

I'd recommend avoiding 302's for now and using a 301 instead, due to Google's demonstrated problem with handling 302s.

Jim

olaf

6:56 am on Nov 22, 2005 (gmt 0)

10+ Year Member



If I understand you right you are talking about the good old way with adding redirect commands to the .htaccess file like:

RedirectPermanent /old_file.php?lang=nl&country=BE [domain.nl...]

What I try is a more flexible way with the help of php. Based on the requested file to send diff. headers and redirects to diff. pages. That is to handle 404 and 301 on a diff. way.

by the way, thanks for helping so far.