Pathauto
Pathauto builds URL aliases from patterns such as /blog/[node:title], so items of one type get consistent addresses without anyone typing them.
Pathauto is a contributed Drupal module that generates URL aliases automatically. You define patterns made of fixed text and tokens, and Pathauto builds an alias from them whenever an item is saved. It covers nodes, taxonomy terms and users. It builds on the core Path module and needs the Token module.
How Pathauto works in Drupal 11
Patterns are the core of the module. The Patterns page at /admin/config/search/path/patterns creates, edits and reorders them. According to the module's help text, an alias comes from the first pattern that applies. Pathauto adds a computed "URL alias" field to every enabled entity type and replaces the path widget with its own.
The Settings page at /admin/config/search/path/settings controls how aliases are built:
- Update action: do nothing and leave the old alias, create a new alias and keep the old one working, or create a new alias and delete the old one. The install configuration of 8.x-1.15 sets the third option.
- Separator: the character that replaces spaces and punctuation; the install configuration uses a hyphen.
- Maximum alias length and maximum component length: the form calls 100 the recommended value for both.
- Reduce strings to letters and numbers: keeps only characters from the ASCII-96 set.
- Character case: converts token values to lowercase. Fixed text in the pattern is not affected.
Two more pages do bulk work. /admin/config/search/path/update_bulk generates aliases for items that have none, which suits a site that installs Pathauto after content exists. /admin/config/search/path/delete_bulk removes aliases that Pathauto created.
On the edit form, the widget shows a "Generate automatic URL alias" checkbox. While it is checked, the manual alias field is disabled. If no pattern applies to the item, the checkbox does not appear.
Example
The module's own tests use the pattern /content/[node:title] for content items. A node titled "Sample article" gets the alias /content/sample-article. Pathauto lowercases the title and replaces the space with the separator. The part in square brackets is a token.
Common mistakes
- Expecting a changed pattern to rewrite old aliases. Run Bulk generate and pick an option that updates existing aliases. The Update and Regenerate options appear only when the update setting does not ignore existing aliases.
- Deleting the old alias without a redirect. The third update action removes the old address. Install the Redirect module, which the Pathauto project recommends, so old links keep working.
- Setting a maximum length above the database column. The help text says the limit should fit the alias column and leave room for suffixes.
- Looking for the checkbox on an item without a pattern. No pattern means no automatic alias.
For marketing and content teams
A pattern decides the alias of every new item of a type, so agree on patterns before you publish or migrate content. After that, editors can leave the checkbox on and concentrate on a good title. Because the update action may change the alias when a title changes, ask your developer which action the site uses before you edit titles on published pages.
With DXPR
The DXPR CMS project page says its clean, SEO-friendly URLs are generated with Pathauto. See DXPR CMS.
Sources
- Drupal.org: Pathauto project
- Drupal.org: Pathauto documentation
- Pathauto 8.x-1.15: routing
- Pathauto 8.x-1.15: help text
- Pathauto 8.x-1.15: info file
- Pathauto 8.x-1.15: settings form
- Pathauto 8.x-1.15: bulk update form
- Pathauto 8.x-1.15: PathautoWidget
- Pathauto 8.x-1.15: PathautoGeneratorInterface
- Pathauto 8.x-1.15: default settings
- Pathauto 8.x-1.15: node tests
- Drupal.org: Redirect project
- Drupal.org: DXPR CMS project