Index: pathauto_taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_taxonomy.inc,v
retrieving revision 1.20.4.18
diff -u -r1.20.4.18 pathauto_taxonomy.inc
--- pathauto_taxonomy.inc	25 Nov 2007 15:57:41 -0000	1.20.4.18
+++ pathauto_taxonomy.inc	5 Dec 2007 00:30:44 -0000
@@ -55,7 +55,7 @@
   $count = 0;
   $placeholders = array();
   while ($category = db_fetch_object($result)) {
-    $count = _taxonomy_pathauto_alias($category, 'bulkupdate') + $count;
+    $count += _taxonomy_pathauto_alias($category, 'bulkupdate');
   }
   
   drupal_set_message(format_plural($count,
Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.1.2.19
diff -u -r1.1.2.19 pathauto.inc
--- pathauto.inc	19 Nov 2007 22:18:27 -0000	1.1.2.19
+++ pathauto.inc	5 Dec 2007 00:30:43 -0000
@@ -63,6 +63,39 @@
 }
 
 /**
+ * Returns old alias and pid if there is already an alias pointing to a different item
+ * 
+ * @param string $src
+ *   A string that is the internal path
+ * 
+ */
+function _pathauto_existing_alias_data ($src) {
+  $output = array(
+    'pid' => '',
+    'old_alias' => ''
+  );
+  $result = db_query("SELECT pid, dst FROM {url_alias} WHERE src='%s'", $src);
+  if ($data = db_fetch_object($result)) {
+    // The item is already aliased, check what to do...
+    switch (variable_get('pathauto_update_action', 2)) {
+      // Replace old alias - remember the pid to update
+      case 2:
+      case 3:
+        $output['pid'] = $data->pid;
+      // Add new alias in addition to old one
+      case 1:
+        $output['old_alias'] = $data->dst;
+        break;
+      // Do nothing
+      case 0:
+      default:
+        break;
+    }
+  }
+  return $output;
+}
+
+/**
  * Clean up a string value provided by a module, resulting in a
  * string containing only alphanumerics and separators
  * @param $string
@@ -193,31 +226,29 @@
     return '';
   }
 
+  if ($module == 'taxonomy') {
+    // Get proper path for term.
+    $term_path = taxonomy_term_path(taxonomy_get_term($entity_id));
+    if ($term_path != $src) {
+      // Quietly alias 'taxonomy/term/[tid]' with proper path for term.
+      $update_data = _pathauto_existing_alias_data($src);
+      _pathauto_set_alias($src, $term_path, $module, $entity_id, $update_data['pid'], FALSE, $update_data['old_alias']);
+      // Set $src as proper path.
+      $src = $term_path;
+    }
+  }
+  
   // Special handling when updating an item which is already aliased.
   $pid = NULL;
   $old_alias = NULL;
   if ($op == 'update' or $op == 'bulkupdate') {
-    $result = db_query("SELECT pid, dst FROM {url_alias} WHERE src='%s'", $src);
-    if ($data = db_fetch_object($result)) {
-      // The item is already aliased, check what to do...
-      switch (variable_get('pathauto_update_action', 2)) {
-        // Do nothing
-        case 0:
-          return '';
-        // Add new alias in addition to old one
-        case 1:
-          $old_alias = $data->dst;
-          break;
-        // Replace old alias - remember the pid to update
-        case 2:
-        case 3:
-          $pid = $data->pid;
-          $old_alias = $data->dst;
-          break;
-        default:
-          break;
-      }
-    }
+    if (variable_get('pathauto_update_action', 2) == 0) {
+      // Do nothing
+      return '';
+    }
+    $update_data = _pathauto_existing_alias_data($src);
+    $pid = $update_data['pid'];
+    $old_alias = $update_data['old_alias'];
   }
 
   // Replace the placeholders with the values provided by the module,
@@ -255,12 +286,9 @@
   // by the module
   if (variable_get('pathauto_'. $module .'_applytofeeds', FALSE)) {
     $feedappend = variable_get('pathauto_'. $module .'_supportsfeeds', '');
-    // If we're in a forum, the src doesn't form the base of the rss feed
-    // TODO refactor this out
-    if ($module == 'forum') {
-      $pieces = explode('/', $src);
-      $tid = $pieces[1];
-      _pathauto_set_alias("taxonomy/term/$tid/$feedappend", "$alias/feed", $module, $entity_id, NULL, $verbose);
+    // For forums and taxonomies, the src doesn't always form the base of the rss feed (ie. image galleries)
+    if ($module == 'taxonomy' || $module == 'forum') {
+      _pathauto_set_alias("taxonomy/term/$entity_id/$feedappend", "$alias/feed", $module, $entity_id, NULL, $verbose);
     }
     else {
       _pathauto_set_alias("$src/$feedappend", "$alias/feed", $module, $entity_id, NULL, $verbose);
Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.44.4.61
diff -u -r1.44.4.61 pathauto.module
--- pathauto.module	25 Nov 2007 15:57:41 -0000	1.44.4.61
+++ pathauto.module	5 Dec 2007 00:30:44 -0000
@@ -650,6 +650,7 @@
           //If the category is deleted, remove the path aliases
           $category = (object) $object;
           path_set_alias('taxonomy/term/'. $category->tid);
+          path_set_alias(taxonomy_term_path($category));
           path_set_alias('forum/'. $category->tid);
           path_set_alias('taxonomy/term/'. $category->tid .'/0/feed');
           break;
