Sunday, August 5, 2007

Don't Be Too Smart

Beware a Header Status of 200 – on "smart 404" pages. I have been told Googlebot requests a url that it knows doesn’t exists. And if your server returns a page with status 200, the Googlebot brands your site a ‘liar’ and will tell you so, too!

I seem to be safe as w3c says
Sorry! This document can not be checked. I got the following unexpected response when trying to retrieve <http://www.tubal-reversal.net/404>: 404 Not Found

Thursday, August 2, 2007

A Smart 404 error

No more broken links, relevant content served up to all requests.

I created a smart error page script that will search our database and return results instead of 404.

The page: www.tubal-reversal.net/tr
does not exist until someone calls it!

if you want the code here it is:
<?php
$search_term = preg_replace("#/$#","",$REQUEST_URI);
ereg("([^\\/]*)$", $search_term, $regs);
$search_term = $regs[1];
/* there must be a better way of stripping file extensions please let me know */
$search_term = ereg_replace(".htm", "", $search_term);
$search_term = ereg_replace(".html", "", $search_term);
$search_term = ereg_replace(".php", "", $search_term);
$search_url = 'http://your-site.com/search.php?q=';
/* or google: $search_url = 'http://www.google.com/search?sitesearch=your-site.com&q='; */
$full_search_url = $search_url . $search_term;
$file = file_get_contents ($full_search_url);
Echo $file;
?>