Genuine 404s and Google Verification

Google is steadily building up it’s webmaster tools and winning over the hearts of webmasters. As covered in my Google Sitemaps and Verification post the feedback can be very, very useful.

I have run into problems though on Mambo and Joomla sites because they don’t throw true 404s so as far as GoogleBot knows every page is a good page. Google and Googlebot have given webmasters an incentive to change… access to the stats!

To get Mambo and Joomla to throw a 404 you need three things!

  1. Create a page using the Static Content editor with a message for users
  2. Create a menu item for
  3. make the following hack to the index.php file. Go to line #54 and add in the $pagename variable and extend the if/then/else check for the $Itemid. The $Itemid for the 404 page is hardcoded and retrieved from step #2.

[php]// retrieve some expected url (or form) arguments
$option = trim( strtolower( mosGetParam( $_REQUEST, ‘option’ ) ) );
$Itemid = intval( mosGetParam( $_REQUEST, ‘Itemid’, null ) );
$pagename = mosGetParam($_SERVER,’REQUEST_URI’);

if ($option == ”) {
if ($Itemid) {
$query = “SELECT id, link”
. “\n FROM #__menu”
. “\n WHERE menutype = ‘mainmenu'”
. “\n AND id = ‘$Itemid'”
. “\n AND published = ‘1’”
;
$database->setQuery( $query );
} elseif (empty($pagename)||$pagename == ‘/’) {
$query = “SELECT id, link”
. “\n FROM #__menu”
. “\n WHERE menutype = ‘mainmenu'”
. “\n AND published = 1”
. “\n ORDER BY parent, ordering LIMIT 1”
;
$database->setQuery( $query );
}
else {
//header(‘Status: 404 Not Found’);
header(‘HTTP/1.1 404 Not Found’);
//hardcoded Item Id of the missing page
$query = “SELECT id, link”
. “\n FROM #__menu”
. “\n WHERE menutype = ‘mainmenu'”
. “\n AND id = ’41′”
. “\n AND published = ‘1’”
;
$database->setQuery( $query );
}[/php]

You can test it out over at Property Prophets

Next Steps

I should consider creating a component and getting the index page to search by component name which can be fixed in every instance.

The ideal would be for this to be a standard config option in Mambo and Joomla. After all when you view your logs you’ll see bots requesting haphazard urls testing the integrity of your site. Far better to tell them to go away by feeding them a 404 than have them hammer endlessly at your server.

Categories

Recent Comments

Tags

4 Comments

  1. April 12, 2006

    I’ve just used JooMap to create a sitemap for the site too. It looks like a good product and worked first time 🙂

    It creates the necessary XML files and a nice html version too.

  2. June 6, 2006

    Sweet! Just what I was looking for. I saw alot of other fixs, like disabling the htaccess file and then re-enabling it after verification…didn’t really trust that method though as it seems like a short cut.

  3. August 20, 2006

    In one of my sites I needed to have

    header(“HTTP/1.1 200 OK”);

    in the pagename section of the if statement

  4. August 30, 2006

    A slight enhancement, a lot of the internal Joomla urls assume that /index.php should give the homepage, so I altered the elseif to read as follows :
    elseif (empty($pagename)||$pagename == ‘/’||$pagename == ‘/index.php’)

    Otherwise fantastic, lets hope someone from the Joomla team picks this up and puts it into core 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.