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.

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

3 Answers 3

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.

2
  • I believe there hasn't been a release of this module for D7 Commented Mar 8, 2012 at 22:37
  • There is a development snapshot for Drupal 7 that is currently available from the project page.
    – avpaderno
    Commented Mar 14, 2012 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']);
    }
  }
}
1
  • 2
    menu_get_item() is only available when Drupal completes its bootstrap, while hook_boot() implementations are invoked in the second bootstrap phase.
    – avpaderno
    Commented Mar 9, 2012 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 and acknowledge you have read our privacy policy.

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