I create a 404 page on D7 site ( ie. mysite.com/404), which is a Basic Page. I am trying to hide the header and footer from this page. The header and footer are blocks, and they are placed in every page using Context. I tried tweaking the Context so that if Path = 404, hide the header and footer.

It works when I go to mysite.com/404. However I try to hit an alias that doesn't exist (ie. mysite.com/asdf), instead of redirecting to /404, Drupal pulls the node body of the 404 page and stay at /asdf. The rule in the Context therefore doesn't apply.

I don't want to use the Visibility control in the Block module because migrating the configuration between sites can be troublesome. How would you go about it?

1 Answer 1


I do this by overriding the template used by the theme. In the template.php:

 * Set path to page-error.tpl if http error is returned.
function yourtheme_preprocess_page(&$vars) {
  // Set custom error template:
  $http_status = drupal_get_http_header("status");

  if (isset($http_status)) {

    switch ($http_status) {
      case "403 Forbidden":
      case "404 Not Found":
      case "500 Internal Server Error":
        $vars['theme_hook_suggestions'][] = 'page__error';
        $vars['http_status'] = "Error: " . $http_status;
        $vars['error_message'] = drupal_get_messages();

Then you can create page--error.tpl.php in your templates directory using whatever regions you want to display. This has added the benefit of automating error pages, so you don't have to set a path in the site config.

  • Hi Adam, The "page--error.tpl.php" solution didn't work for me, but altering templates.php did the trick. Thank you very much!! Oct 16, 2014 at 21:03
  • Glad you got it working- fyi you can get the page--error.tpl working by adding: if (isset($vars['node']->type)) { $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type; }
    – adam_bear
    Oct 17, 2014 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.