--- taxonomy_manager.admin.inc	2010-01-31 13:17:27.000000000 -0430
+++ taxonomy_manager.admin.inc_new	2011-02-23 21:43:19.000000000 -0430
@@ -572,7 +572,13 @@ function taxonomy_manager_merge_form($vo
   $options['collect_parents'] = t('Collect all parents of selected terms an add it to the merged term'); 
   $options['collect_children'] = t('Collect all children of selected terms an add it to the merged term');
   $options['collect_relations'] = t('Collect all relations of selected terms an add it to the merged term');
-  
+
+  // If path_redirect is installed, also give an option to allow merged terms
+  // to have their old URLs merged to the new one.
+  if (module_exists('path_redirect')) {
+    $options['merge_redirect'] = t('Use path_redirect to redirect all old URLs to the new term.'); 
+  }
+
   if (count($options) > 0) {
     $form['merge']['options'] = array( 
       '#type' => 'checkboxes', 
@@ -580,7 +586,11 @@ function taxonomy_manager_merge_form($vo
       '#options' => $options, 
     );
   }
-   
+
+  if (module_exists('path_redirect')) {
+    $form['merge']['options']['#default_value'] = array('merge_redirect');
+  }
+
   $form['merge']['submit'] = array( 
     '#type' => 'submit', 
     '#value' => t('Merge'),
@@ -2120,7 +2130,42 @@ function taxonomy_manager_merge($main_te
   
   foreach ($merging_terms as $merge_term) {
     if ($merge_term != $main_term) {
-      
+
+      // If path_redirect is installed and 'merge_redirect' option is set,
+      // create redirects for the old URL.
+      if (module_exists('path_redirect') && $options['merge_redirect']) {
+        // Redirect the old base URL.
+        $redirect = array(
+          'source' => 'taxonomy/term/' . $merge_term,
+          'redirect' => 'taxonomy/term/' . $main_term,
+        );
+        path_redirect_save($redirect);
+        // Redirect any optional URL aliases.
+        $aliases = db_query("SELECT dst FROM {url_alias} WHERE src='%s'", $redirect['source']);
+        while ($alias = db_fetch_object($aliases)) {
+          // Want to make sure we're inserting a new record.
+          unset($redirect['rid']);
+          // The old destination is the new source path.
+          $redirect['source'] = $alias->dst;
+          // Save the new redirect.
+          path_redirect_save($redirect);
+        }
+        // Cleanup any old path_redirect recordss
+        $aliases = db_query("SELECT rid, source FROM {path_redirect} WHERE redirect='%s'", $redirect['source']);
+        while ($alias = db_fetch_object($aliases)) {
+          // Make sure we're updating the correct record.
+          $redirect['rid'] = $alias->rid;
+          // The old path is the new source path.
+          $redirect['source'] = $alias->source;
+          // Save the new redirect.
+          path_redirect_save($redirect);
+        }
+        // Cleanup.
+        unset($alias);
+        unset($aliases);
+        unset($redirect);
+      }
+
       //hook, to inform other modules about the changes
       module_invoke_all('taxonomy_manager_term', 'merge', $main_term, $merge_term);
       
