--- search404.module.original	2009-08-07 16:39:12.000000000 +0200
+++ search404.module	2009-08-07 16:38:39.000000000 +0200
@@ -5,20 +5,20 @@
  */
 function search404_menu() {
   $items = array();
-  
+
   $items['search404'] = array(
-    'title' => t('Page not found'), 
-		'access callback' => TRUE,
+    'title' => t('Page not found'),
+    'access callback' => TRUE,
     'page callback' => 'search404_page',
-		'type' => MENU_LOCAL_TASK
-	);
-	
+    'type' => MENU_LOCAL_TASK
+  );
+
   $items['admin/settings/search404'] = array(
     'title' => t('Search 404 settings'),
     'description' => t('Administer search 404.'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('search404_settings'),
-		'access callback' => 'user_access',
+    'access callback' => 'user_access',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM,
   );
@@ -42,7 +42,7 @@ function search404_get_keys() {
   $regex_filter = variable_get('search404_regex', '');
   $keys_array[] = $keys;
   if (!empty($regex_filter)) {
-	  $keys = preg_replace("/".$regex_filter."/", '', $keys);
+    $keys = preg_replace("/".$regex_filter."/", '', $keys);
  }
   // Ingore certain extensions from query
   $extensions = preg_split('/\s+/', variable_get('search404_ignore_extensions', 'htm html php'));
@@ -108,56 +108,88 @@ function search404_page() {
       $keys = search404_search_engine_query();
     }
     if (!$keys) {
-      $keys = search404_get_keys();
+      if (variable_get('search404_custom_page', '') == '') {
+        // If no custom page has be set, display the default search form
+        $keys = search404_get_keys();
+      } else {
+        // Redirect to the custom page
+        drupal_goto ( variable_get('search404_custom_page',''), NULL ,NULL , 301);
+      }
     }
     if ($keys) {
       // TODO: watchdog?
       if (module_exists('google') && user_access('search Google CSE') && variable_get('search404_do_google_cse', false)) {
-        drupal_set_message(t('The page you requested does not exist. For your convenience, a google search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
-        drupal_goto ('search/google/'. $keys);
+        if (!variable_get('search404_disable_warning', false)) {
+          drupal_set_message(t('The page you requested does not exist. For your convenience, a google search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
+        }
+        if (variable_get('search404_redirect_301', false)) {
+          drupal_goto ('search/google/'. $keys , NULL ,NULL , 301);
+        } else {
+          drupal_goto ('search/google/'. $keys);
+        }
       } else {
         $results = module_invoke($type_search, 'search', 'search', $keys);
         if (isset($results) && is_array($results) && count($results) == 1 && variable_get('search404_jump', false)) {
           // First, check to see if there is exactly 1 result
-          drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
+          if (!variable_get('search404_disable_warning', false)) {
+            drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
+          }
           // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
           $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;
-          drupal_goto();
+          if (variable_get('search404_redirect_301', false)) {
+            drupal_goto ("" , NULL ,NULL , 301);
+          } else {
+            drupal_goto();
+          }
         }
         elseif (isset($results) && is_array($results) && count($results) > 1 && variable_get('search404_first', false)) {
-          drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
+          if (!variable_get('search404_disable_warning', false)) {
+            drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
+          }
           // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
           $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;
-          drupal_goto();
+          if (variable_get('search404_redirect_301', false)) {
+            drupal_goto ("" , NULL ,NULL , 301);
+          } else {
+            drupal_goto();
+          }
         }
         else {
-          drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
-          if (isset($results) && is_array($results) && count($results) > 0) {
-            drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);
-            // EVIL HAXX!
-              $oldgetq = $_GET['q'];
-              $olddestination = $_REQUEST['destination'];
-              unset($_REQUEST['destination']);
-              $_GET['q'] = "search/$type_search/$keys";
-              $results = theme('search_results', $results, 'node');
-              $_GET['q'] = $oldgetq;
-              $_REQUEST['destination'] = $olddestination;
-            // END OF EVIL HAXX!
-          }
-          else {
-            $results = search_help('search#noresults', drupal_help_arg());
+          if (variable_get('search404_custom_page', '') == '') {
+            // If no custom page has be set, display the default search form
+            if (!variable_get('search404_disable_warning', false)) {
+              drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
+            }
+            if (isset($results) && is_array($results) && count($results) > 0) {
+              drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);
+              // EVIL HAXX!
+                $oldgetq = $_GET['q'];
+                $olddestination = $_REQUEST['destination'];
+                unset($_REQUEST['destination']);
+                $_GET['q'] = "search/$type_search/$keys";
+                $results = theme('search_results', $results, 'node');
+                $_GET['q'] = $oldgetq;
+                $_REQUEST['destination'] = $olddestination;
+              // END OF EVIL HAXX!
+            }
+            else {
+              $results = search_help('search#noresults', drupal_help_arg());
+            }
+            $results = theme('box', t('Search results'), $results);
+          } else {
+            // Redirect to the custom page
+            drupal_goto ( variable_get('search404_custom_page',''), NULL ,NULL , 301);
           }
-          $results = theme('box', t('Search results'), $results);
         }
       }
     }
     // Construct the search form.
     $output = drupal_get_form('search_form', NULL, $keys, $type_search) . $results;
   }
-  
+
   /*
    * Start EVIL HAXX 2
-   * This was done to display sidebars left and right of page, if the option is set from Search404 
+   * This was done to display sidebars left and right of page, if the option is set from Search404
    * Settings Page.
    */
   if (variable_get('search404_block_show', false)) {
@@ -167,7 +199,7 @@ function search404_page() {
     exit (0);
   }
   else {
-    return $output;    
+    return $output;
   }
   // End of EVIL HAXX 2
 
@@ -193,7 +225,29 @@ function search404_settings() {
     '#title' => t('Show left and right sidebars in page when a 404 search occurs'),
     '#default_value' => variable_get('search404_block_show', false),
   );
-  
+  //Added for having a 301 redirect instead of the standard 302 (offered by the drupal_goto)
+  $form['search404_redirect_301'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use a redirect 301 instead of redirect 302'),
+    '#default_value' => variable_get('search404_redirect_301', false),
+  );
+
+  //Disable warning message
+  $form['search404_disable_warning'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Disable the warning message when an user is redirect to a search result'),
+    '#default_value' => variable_get('search404_disable_warning', false),
+  );
+
+
+  //Redirect to a custom page instead of display the drupal search form
+  $form['search404_custom_page'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Custom page if no nodes has been found'),
+    '#description' => t('This page will be displayed if no nodes will be found. Leave blank to disable this option.'),
+    '#default_value' => variable_get('search404_custom_page', ''),
+  );
+
   $form['search404_do_google_cse'] = array(
     '#type' => 'checkbox',
     '#title' => t('Do a Google CSE Search instead of a Drupal Search when a 404 Occurs'),
@@ -201,7 +255,7 @@ function search404_settings() {
     '#attributes' => module_exists('google') ? array()  : array ('disabled' => 'disabled'),
     '#default_value' => variable_get('search404_do_google_cse', false),
   );
-  
+
   $form['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
