An alternative to Pathauto

Pathauto is an awesome module, but there may be a time when, for one reason or another, don't want or don't need to use it.

custom_url_rewrite is a function (not a hook) available in Drupal which gives you an alternative to configuring custom paths and storing them in the database.

Since this is not a hook, it is suggested you put this in settings.php. You can convert the alias into the source, and vice versa.

There's a great code example in the API link above which shows a few examples of what you can do with this function including changing 'node/' to 'article/' and changing the user's profile page from 'user/1' to 'e'. I'll take it a step further and demonstrate how to change 'node/1' to something like 'stories/1-my-big-long-story-title'.

You can use preg_match to find a node id and query for the node type and title. Based on the type, you could then incorporate the title into the url for the 'alias' operation.

In the 'source' operation, you could then use preg_match again to change the request back to 'node/' without even having to add an item to the menu hook. This exact code isn't tested, but it would look something like this:

<?phpfunction custom_url_rewrite($op, $result, $path) {  global $user;  if ($op == 'alias') {    // Change all 'node' to 'stories/<nid>-title'.    if (preg_match('|^node/([0-9]+)$|', $path, $matches)) {      $node = db_fetch_object(db_query("SELECT nid, type, title FROM {node} WHERE nid=%d", $matches[1]));            if ($type=='story') {        return 'stories/'. $node->nid .'-'. strtolower(preg_replace('/\W/', '-', $node->title));      }    }  }  if ($op == 'source') {    // Change 'stories' back to 'node'    if (preg_match('|^stories/([0-9]+)-|', $path, $matches)) {      return 'node/'. $matches[1];    }  }  // Do not forget to return $result!  return $result;}?>

You need to consider that this function is going to be called anytime l() or url() are called, so you could seriously put a lot more load on the server if you have anything too heavy in there.