404 foolishness

Photo of Greg Harvey
Thu, 2008-02-21 19:33By greg

I finally bothered to get to the bottom of a behaviour I'd noticed some time ago but never investigated. When showing a 404 page, custom or otherwise, Drupal 5.x (and now Drupal 6.x too) does not render any blocks. Not only does this drop your user in to no-man's land on your site, but it also breaks some layouts too, depending on your theme.

There has been a load of debate about this, culminating in the creation of this (broken, btw - I made a new one) patch:
http://drupal.org/node/141162

The solution is simple - even more simple than this patch. Find these lines in common.inc:

// To conserve CPU and bandwidth, omit the blocks
print theme('page', $return, TRUE);
?>

And replace them thus:

// Begone, oh silliness of Drupalite nincompoops!
print theme('page', $return, FALSE);
?>

That's all there is to it. Now your 404 page will render blocks again, presuming you have any switched on for the page concerned.

As you can see from the accompanying comment, the reason the Drupal core developers decided to impose this lack of blocks on everyone is because they feel allocating unnecessary processing to an error page is a waste of system resources. They cite examples where the 404 page is hit millions of times in a month.

Fine, so you get hit a lot. But I say simply disabling blocks on the 404 page is the lamest and laziest way of dealing with the performance issue. You're not DEALING WITH THE ISSUE. You're just hiding it and buying yourself a little more time.

"Erm, these 404s are causing performance issues..."
"Let's just return nothing then!"

Guys, that just SUCKS. Sheesh, what were they thinking? What's worse is most of the core developers still seem to think this is a good idea. Fortunately a compromise has been forged for Drupal 7. So we only have two years of patching Drupal 6.x ahead of us. Doh!!