1

Just wondering if there is a simple way to automatically redirect users to the last page they have visited if they receive a 404 error? I am using Drupal 7.

  • 6
    Wouldn't that be awfully confusing for your users? – Clive Mar 8 '12 at 22:13
  • it was a lazy work around for a view I had. Ended up doing something entirely different. – Miller Mar 9 '12 at 0:14
2

There's a module for that: CustomError, which has a development snapshot for Drupal 7.

This module allows the site admin to create custom error pages for 404 (not found), and 403 (access denied), without the need to create nodes for each of them.

Since the error pages are not real nodes, they do not belong a category term, they do not show in the search, and will not show up in node listings, or in Popular Content block.

  • I believe there hasn't been a release of this module for D7 – Alex Petrov Mar 8 '12 at 22:37
  • There is a development snapshot for Drupal 7 that is currently available from the project page. – kiamlaluno Mar 14 '12 at 7:43
1

You can do this with a custom module:

function YOUR_MODULE_NAME_boot() {
  if(!menu_get_item($_GET['q'])) {
    if($_SERVER['HTTP_REFERRER']) {
      header('Location: ' . $_SERVER['HTTP_REFERRER']);
    }
  }
}
  • 2
    menu_get_item() is only available when Drupal completes its bootstrap, while hook_boot() implementations are invoked in the second bootstrap phase. – kiamlaluno Mar 9 '12 at 3:21
1

Instead of redirecting users automatically, I suggest you provide a link in the 404 page to link back to the previous page. You can make use of HTTP_REFERRER to link back, or any other approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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