Pathauto
We have seen how to use the Path module to create specific URL aliases for special pages.
When it comes to our bulk content, such as the recipes on cookieiwki.com, it can be quite tedious having to come up with an alias for each recipe, especially if your site allows authenticated users to enter content. There are various problems:
- You might forget to enter an alias sometimes. Some recipes will than have a random node path (eg node/2168) instead of a path which reflects the recipe title, simply because a user forgot to set the path alias.
- If you want a consistent system (such as recipe/[recipe-title-with hyphens-instead-of-spaces]) it can be hard to police. Even if you are the only person editing your site, inconsistencies can creep in.
- If a recipe title changes, it is easy to forget to update the path to reflect this.
- It isn't a good idea to give users complete control over the path, this can be a security risk (see later in this section).
Pathauto allows you to assign path aliases to content automatically, according to detailed rules. This means that neither you nor your users have to think at all about creating aliases, it just happens.
What Pathauto does
It is important to understand what Pathauto does.
The Path module maintains a list of path aliases. Eg someone clicks on www.cookiewiki.com/about, and node/7 has the alias about, then Path will cause Drupal to serve up the contents of node/7.
Pathauto works on a different level. It creates aliases automatically, then leaves it up to Path to handle incoming requests. Pathauto, therefore, only does any work at specific times:
- If new content is created, Pathauto creates an alias.
- If content changes (eg its title is changed), Pathauto changes the alias if necessary.
- In certain circumstances, eg if the rules for Pathauto are changed, then Pathauto might have to change a number (maybe a large number) of aliases. This is called a bulk update.
