--- taxonomy_manager.admin.inc	2009-09-05 16:09:41.000000000 +0600
+++ taxonomy_manager.admin.inc	2009-12-19 00:57:40.000000000 +0500
@@ -572,14 +572,23 @@ function taxonomy_manager_merge_form($vo
   $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', 
       '#title' => t('Options'), 
       '#options' => $options, 
     );
+    if (module_exists('path_redirect')) {
+      $form['merge']['options']['#default_value'] = array('merge_redirect');
+    }
   }
-   
+
   $form['merge']['submit'] = array( 
     '#type' => 'submit', 
     '#value' => t('Merge'),
@@ -2118,6 +2127,41 @@ function taxonomy_manager_merge($main_te
   //TODO: add hook, so that other modules can consider changes
   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);
+      }
+
       //update node-relations
       $sql = db_query("SELECT * FROM {term_node} WHERE tid = %d", $merge_term);
       while ($obj = db_fetch_object($sql)) {
