Index: index.php
===================================================================
RCS file: /cvs/drupal/drupal/index.php,v
retrieving revision 1.90
diff -u -r1.90 index.php
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.529
diff -u -r1.529 common.inc
--- includes/common.inc	28 Mar 2006 09:29:23 -0000	1.529
+++ includes/common.inc	3 Apr 2006 19:00:44 -0000
@@ -255,6 +255,11 @@
   drupal_set_header('HTTP/1.0 404 Not Found');
   watchdog('page not found', t('%page not found.', array('%page' => theme('placeholder', $_GET['q']))), WATCHDOG_WARNING);
 
+  // Keep old path for reference
+  if (!isset($_REQUEST['destination'])) {
+    $_REQUEST['destination'] = $_GET['q'];
+  }
+
   $path = drupal_get_normal_path(variable_get('site_404', ''));
   if ($path && $path != $_GET['q']) {
     menu_set_active_item($path);
@@ -262,7 +267,7 @@
   }
   else {
     // Redirect to a non-existant menu item to make possible tabs disappear.
-    menu_set_active_item('#');
+    menu_set_active_item('');
   }
 
   if (empty($return)) {
@@ -278,6 +283,11 @@
   drupal_set_header('HTTP/1.0 403 Forbidden');
   watchdog('access denied', t('%page denied access.', array('%page' => theme('placeholder', $_GET['q']))), WATCHDOG_WARNING, l(t('view'), $_GET['q']));
 
+  // Keep old path for reference
+  if (!isset($_REQUEST['destination'])) {
+    $_REQUEST['destination'] = $_GET['q'];
+  }
+
   $path = drupal_get_normal_path(variable_get('site_403', ''));
   if ($path && $path != $_GET['q']) {
     menu_set_active_item($path);
@@ -285,7 +295,7 @@
   }
   else {
     // Redirect to a non-existant menu item to make possible tabs disappear.
-    menu_set_active_item('#');
+    menu_set_active_item('');
   }
 
   if (empty($return)) {
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.112
diff -u -r1.112 menu.inc
--- includes/menu.inc	20 Mar 2006 20:48:19 -0000	1.112
+++ includes/menu.inc	3 Apr 2006 19:00:49 -0000
@@ -428,8 +428,8 @@
   static $stored_mid;
   $menu = menu_get_menu();
 
-  if (is_null($stored_mid) || !empty($path)) {
-    if (empty($path)) {
+  if (!isset($stored_mid) || isset($path)) {
+    if (!isset($path)) {
       $path = $_GET['q'];
     }
     else {
