Forum Moderators: phranque
eg if we have a page like this
www.mydomain.com/page/1.htm running from a database where data is displayed matching the variable 1 all is fine - but if someone changes the 1 to 1000 and there is no matching data in the database the page will be displayed but empty of data - ideally I want this to become a 404 for example just as it does at WebmasterWorld:-
www.webmasterworld.com/forum1/ - data pulled from database
www.webmasterworld.com/forum1000/ - database must be queried to see if forum exists and then 404 served as no matching data.
I have gone for a PHP Header Redirect by first checking to see if data is returned based on the typed in url and then if nothing returned gone for a PHP Header Redirect to the 404.
Instead, use the php header function to return a 404 status code, and then directly output your 404 error page contents from that same script.
Jim
The code I was using is as follows:-
<?php if($data== ""){
header("HTTP/1.0 404 Not Found");
header("Location: file/404error.htm");
exit;
}
?>
Does this look OK?
Thanks for your help.
Returning a 302 response to a 'bot in response to a request for a page that does not exist can be a disaster. First, you'll end up with duplicate content -- many copies of the 404 page itself, and second, your server will appear to be an "infinite URL space" to the 'bots, since no matter what URL they ask for, they'll get a 302 redirect to a page that exists (the 404 page). In this case, several 'bots are known to set a strict limit on how deep they'll spider your site -- They do not want to waste time on sites that will generate a page for any query, because it is a waste of their spidering resources and bloats their index with likely-to-be-useless auto-generated pages.
I'd consider getting this problem fixed to be a very high priority.
Jim
I have removed the redirects for now :)
So if I use the following code:-
<?php if($data== ""){
header("HTTP/1.0 404 Not Found");
exit;
}
?>
The robots will see a 404 page? - the user will still go to the database page with no database content but at least the robots will see a 404 and I can hand code the database page for empty content?
No, the robots. will see a 404 server response code. I cannot answer what your script will do as far as providing the content-body of the response -- that is up to your script. As far as the robots are concerned, a 404 response code is all they really care about, but in addition to that, you should return 'friendlier' content for your type-in users.
You may want to ask about this over in the PHP forum if you don't get more-informed responses here.
Jim