Replace rewrite output URL aliases Is it possible to rewrite parts of taxonomy terms URL custom aliases before output, for example with something similar to the the following code?

  function replace_term_url ($term_alias) {
    // Url alias "article/first"
    $term_alias = str_replace("article", "article-sub", $term_alias);
  }
In Drupal 7 there isn't a specific hook to alter the URL associated with a taxonomy term, but you can use the generic hooks for altering URLs, which are hook_url_inbound_alter(), and hook_url_outbound_alter().

function mymodule_url_outbound_alter(&amp;$path, &amp;$options, $original_path) {
  if (preg_match('|^taxonomy/term/([0-9]*)|', $path, $matches)) {
    // Alter $path; $matches[1] contains the term ID.
  }
}

function mymodule_url_inbound_alter(&amp;$path, $original_path, $path_language) {
  // Revert the change done in mymodule_url_outbound_alter().
}


hook_url_outbound_alter() is invoked for URLs output from Drupal, hook_url_inbound_alter() is invoked for URLs Drupal is receiving.

In Drupal 6, it is possible to implement hook_term_path(), but that is invoked only for the module associated with the taxonomy term. The code invoking that hook is in taxonomy_term_path().

  if ($vocabulary-&gt;module != 'taxonomy' &amp;&amp; $path = module_invoke($vocabulary-&gt;module, 'term_path', $term)) {
    return $path;
  }


If you want to use a third-party module, then there is the Pathauto module, which allows to automatically set the alias for users, nodes, and taxonomy terms.


  The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change.