Forum Moderators: open

Message Too Old, No Replies

how to 404 when data is removed from DB

         

brandon0401

1:30 am on Sep 12, 2007 (gmt 0)

10+ Year Member



hey guys, just wondering what is best to do. We run a database driven content site....and from here and there we will remove content, change servers so some ids will be gone....

Since I was getting 404s when the id was gone, and it wasnt 404, it would show fine, but it would show no content, no title, and bad link to data...I wanted to clean it up

So I check if the id is there, and if not I, in php set the header to 404..

ie

if($detail['title']==''){
header("HTTP/1.1 404 Not Found");
exit();
}
else{
header("HTTP/1.1 200 OK");
}

Well this is working fine to prevent from loading pages with empty data....but it redirects to blank white page in browser...

So wonder how to best do this, there will be differences in links that update in side columns etc, but want to stay away from too much duplicate content...but I also dont want to get people stuck dug in tracks and if there is a page, id like to get use on it if its being read by spiders...

So what does everyone suggest? thanks in advance for your replies!

Brandon

encyclo

1:46 am on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld brandon0401. Once you set the 404 header, add an
include
before the
exit();
which includes a custom 404 page with links to other content. It can be a static page, or if you want to get fancy, see if you can generate a page with links to pages similar to the one removed. :)

brandon0401

2:35 am on Sep 12, 2007 (gmt 0)

10+ Year Member



ok but do you think its good to make it 404 header? even if url will be fine always...just wont have data

and what about including to a 404 page that has a meta refresh that goes back to home page

phranque

4:25 am on Sep 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld brandon0401!

404 means "Not Found" which is precisely the correct usage for this case.

brandon0401

4:43 am on Sep 12, 2007 (gmt 0)

10+ Year Member



ok so it will keep same url though then and keep PR if it had one? thanks

brandon0401

4:47 am on Sep 12, 2007 (gmt 0)

10+ Year Member



and is it ok to redirect to homepage after throwing 404? thanks

encyclo

10:47 am on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As the URL is returning a 404, then the page will eventually dissappear from search results. It will act the same as any random, non-valid URL for your site.

Redirecting to the home page won't affect the search engine, but it is very poor usability as it is confusing to the end user. You should create a 404 page which indicates that the URL cannot be found, and offer alternatives and/or links to other content.

phranque

12:20 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



- you can put anything you want on your 404 page but it should make sense for when a user requests content that isn't found.
- there is no difference between "expected Not Found" (such as deleted content) and "unexpected Not Found" (such as mistyped url). they are both 404's to the user/browser/spider.
- the search engines won't index the 404 page or maintain page rank for a 404 url, even if it eventually refreshes to a valid document.
- if there is truly equivalent content to refresh to, it might make sense to use a 301 instead of a 404.