Drupal navigation on error pages

by John McGeechan

Synopsis

As of drupal 5.x blocks are not processed on 403 and 404 error pages, instead the contents of the specified pages are used along with the site theme to create an error page (or simply the words 'page not found' if no error page has been specified).

This decision was a deliberate one....

Implications

Quite reasonably the Drupal developers decided that a site could be bombarded with potentially thousands of 404's either through an author error - maybe a mistyped or incorrect link in a node - or through intrusive requests from robots and web crawlers. If the 403/404 processing was not made as light as possible this could have a significant overhead.

However, as some have noted, this lack of block processing can result in the error page losing all sense of navigation especially if context and site navigation links are placed within blocks on the page. For novice users it may not be clear what they should do next in the absence of appropriate navigation.

Solutions

There are essentially two solutions to this problem. The first is to simply ensure that the specified 403 and 404 error pages contain enough information to ensure that the user can easily navigate easily back to the appropriate page. This may simply be a link which says 'click here to return home'.

The other solution is to ensure that the blocks are always displayed on a page, even in the event of a 403/404 error. This of course could result in higher processing demand on the server for the reasons outlined above.

Assuming this is not an issue how can we get Drupal to always do the block processing ?

Whatever you do, do not ever hack the drupal core in order to achieve this outcome !! not for this problem or any other. Hacking core code as a means of getting required functionality is always a cul-de-sac solution especially when the correct solution is often much simpler.

Always override core processing, never hack it !

To override the core processing to ensure that the blocks are always processed add the following function to the template.php file

/*
fix to ensure that error page holds navigation blocks
*/

function yourthemename_page($content, $show_blocks = TRUE) {

return phptemplate_page($content, TRUE);

}

Alternatively

If you wish to have navigation blocks but without the overhead of the actual block processing. This can be achieved with a static 403/404 error page. Simply create a page/story that looks just like your existing block navigation and specify these in Administer > Site Configuration > Error Reporting. Obviously a change to the look and feel of the site or  the navigation would require a corresponding change to this page/story. Unfortunately Drupal does not allow you to simply specify an external page as the error page. I am still unclear as to why this may be the case.

There is also the 404 search module

The 404 search module greatly enhances the functionality of the 404 error page.

Can you expand on this please ?

In what way do you mean ?