Forum Moderators: coopster
From time to time, Google Webmaster Tools would show pages under “not found”. Sometimes it happens that when I click onto those links, instead of our custom 404 page, we get “The page cannot be found”. Sometimes we need to refresh this particular web address few times before we get our custom 404 page. On some other occasions it works every time.
Would this be a sign that the server where we host our site is having problems?
The reason why I ask this is the fact that we maintain outgoing links in PHP file. Should I be doubtful if our outgoing links are working every time somebody clicks onto them?
I know that for 404, .htaccess is to be read and then in case of non-existing page to go to custom 404 page.
For “links” PHP file, it is a simple link somewhere from within HTML code of current page.
Should we be worried?
Is there a way of logging all PHP errors and seeing what’s happening?
Would server logs show if clicks onto PHP link file were generating errors?
Many thanks.
I know that IE doesnt use your error page unless it is larger than a something (I cant remember the exact amount, but it is quite small). It maybe something to do with the page getting cached by the browser and so you keep getting the default page...but im guessing, as this isnt a problem I have had with any of my sites.
If you want to check that outgoing links are actually returning the correct response code then you can use cURL to check.
Use the curl_setopt [uk.php.net]($ch, CURLOPT_HEADER, true); to give you access to the header. You can then look for the response code and check that this isnt 404¦410, or 301¦302 if you dont want people redirecting there pages.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$res = curl_exec($ch);
curl_close($ch);
if ($res!== false){
$code = explode($res);
$code = $code[1];
switch ($code){
case '200':
// all ok
break;
case '404':
case '410':
// error
// log files to error_log.txt or whatever
break;
}
}
So (with a little rewriting) you can pass all of you outgoing links through that sctipt i.e. link to example.com becomes /tracker.php?p=example.com (similar to how this forum operates, if you look at the address for any of the external links), or you could use mod_rewrite to send all of the links through that page i.e.
RewriteRule ^http://(.*) /tracker.php?p=$1 [L]
Or you could turn it into a function then pass all of the links through that function with the use of some javascipt.
I would personally go for the first option, as then you will get everyone.