There are frequently requests for how to make certain patterns of URLs for Pathauto.
Basics of Patterns
In general, a pattern is a form of variable substitution. So, when you see the variable
[title-raw] in a pattern, that will be replaced with the title of the node. This system should hopefully be intuitive to most users. A blog post with the title "my blog post" whose pathauto pattern is
[title-raw] would be created with the alias
When the pattern for a node type is left blank when creating the node, the default pattern will be used. But if the default pattern is also blank, Pathauto will be disabled for that node type.
Each of the four content types -- node, user, taxonomy, and blog posts -- has its own list of variables that come by default (and are provided either by the Token module, which is a prerequisite for installing Pathauto, or by the Pathauto module itself). To look at the variables available for a given type, go to:
- For 7.x:Administration > Configuration > Search and metadata > URL aliases, in the "Patterns tab" (admin/config/search/path/patterns).
- For 6.x: Administer > Site Building > URL aliases, in the "Automated alias settings" tab.
- For 5.x: Administer > Site Configuration > Pathauto
click on the settings fieldset in the form for the type you are interested in and then click on 'Replacement Patterns' to see a list of variables allowed for that type.
Filtering and Transliteration
When a pattern is replaced with the actual text there is some filtering and transliteration that may occur. In Pathauto 5.x transliteration is controlled by the existence of the i18n-ascii.txt file. An example file is provided with the download. You can customize this file for your site and then upgrade easily - the version of the file in Pathatuto has .example. in the title so it will not over-write your local changes. If you do not transliterate them to western-ascii then Pathauto currently replaces them with the separator value though in the near future that should be an option.
Note: You have to enable the 'locale' core module and have more than one language enabled in order for Pathauto to support a language-specific automatic aliases.
You can get a little bit more advanced and use static text in your pattern. For example, you could enter a pattern for all blog posts like
blogs/[author-name]/[title-raw] in Drupal 6.x.) This would automatically create all "blog" posts with a prefix of "blogs" followed by the username of the user who posted the item and then the title of the post. Under this pattern my example blog post would get the alias www.example.com/blogs/greggles/my-blog-post
Patterns for Taxonomy Terms (Categories)
There are four tokens available (as of Pathauto2 in D5.1) for use in structuring taxonomy URLs.
If you want to make a simple url out of a taxonomy category that has nothing but numbers in it, i.e., 01 02 03 and so on, you should use lesson/[cat]. This will result in lesson/01, lesson/02, lesson/03, and not lesson/lesson-number-01 as you might suspect. The [cat] token does not list the verbatim name of the category as it implies in the inline instructions. Rather, it substitutes the actual text of the terms themselves, rather than listing the text of the category's name. That would be what [catpath] is for.
Advanced - Use Views and Pathauto to Get Index Aliases
As you can see from the static text example, there is now a concept of directories in my blogs/greggles/my-blog-post alias. Pathauto provides an index alias feature but this is deprecated and will likely be removed in future versions. Instead you can use views to provide the same functionality. For example, if you create a view that has the page url "blogs" and that shows the teasers of all blog posts your site will now handle the www.example.com/blogs. If I then add an argument to that view for "Username: user is author" and select "Display all values" as the default I have created "index aliases" for my pathauto patterns. A site visitor who goes to www.example.com/blogs/greggles/ would now see a list of teasers that were created by greggles. You can take this example even further to support the [yyyy] pattern to filter to a specific time period.
See also this Videocast about Pathauto and Views to get Hackable URLs.
It should also be noted that some patterns can be dangerous when used in Pathauto. These Dangerous Pathauto Patterns are explained in more detail on their own page, but the short version is this: you should generally use a prefix on your paths that has no ability to conflict with Drupal reserved paths/callbacks/directories.
Share your pattern recipes
Feel free to add your own patterns by creating a child page. List your patterns and describe the motivation for doing them and/or how you feel they benefit your site.