The Drupal Pathauto module allows site admins to generate user-friendly URL aliases for different types of content. These user-friendly URLs are extremely vital in boosting your SEO ranking.
By default, Drupal implements a "node/nid" URL path system. When you create your first node in Drupal 8, the default URL path looks like ”/node/1”, and the next one will look like “/node/2” and so on. This not user-friendly nor is it very SEO-friendly. Search engines always prefer URLs that are more descriptive of the page content, clean and legible. Using the Drupal 8 Pathauto module, you can obtain a path that looks like this -> "/category/my-node-title". The Drupal Pathauto module also eliminates the need to manually create path aliases for every type of content on a Drupal site. When you have an existing site with plenty of content, you can leverage the Bulk generate option in the Drupal Pathauto module to automatically generate aliases for them in a jiffy. Let’s learn how to configure and implement this time-saving Drupal module. The Drupal Pathauto module is also Drupal 9 compatible.
What does the Drupal Pathauto Module do?
The Drupal 8 Pathauto module enables automatic generation of URL/path aliases for different kinds of content like nodes, taxonomy terms and users. All of this without the need for the user to manually enter the path alias. So instead of a URL that looks like /node/1, the Drupal Pathauto module lets you create URL aliases like /category/my-node-title. Thus, giving your users a much better idea on what to expect from the web page. Without Drupal Pathauto, creating a URL structure is time-consuming and error-prone. The site admins can specify a pattern to follow for different types of content. The Bulk generate option lets you automatically generate or regenerate aliases for pre-existing content as well.
Getting Started with the Drupal 8 Pathauto module
Installing the Drupal 8 Pathauto module is like installing any other contributed module. I’m using the Composer to install since it automatically installs all of the necessary dependencies and Drush commands to enable the module. However, if you choose to install manually, make sure you also have the latest versions of the CTools and Token modules installed.
Open the terminal, within the project enter the following command.
$ composer require drupal/pathauto
$ drush en pathauto
1. Create Drupal URL alias Patterns
- Configure Pathauto patterns as required in Configuration -> URL aliases -> Patterns.
- Click "Add Pathauto pattern"
- Select the Pattern Type. For example, if you are generating URL aliases for nodes, you should choose “Content” as the Pattern type.
- Add the path pattern to the textbox, and you can browse available tokens for the pattern. When you click on the link, available options will show up. For example, I used the [node:title] pattern. So, the URL will be http://yourdomain.com/node-title
- Select content type or you can also leave it empty. This pattern will be used for all content from the Content Type dropdown.
- Enter the Label field which helps in identification of the pattern.
- Hit the Save button.
- Back on the Patterns tab, you will now see that the Pathauto pattern has now been created
2. Generate Bulk URL aliases
- Go to the Bulk generate tab for the entity type you want to bulk generate the aliases and click Update.
- Now you have created the URL aliases automatically.
- Now Click on one of the Alias just generated and the page will display the Content with the user-friendly URL as shown below
3. Deleting Aliases
You can also batch delete aliases from the “Delete aliases” tab. You can either choose the entity types you want to delete, or you can bulk delete all aliases. You can choose to delete the aliases that you automatically generated. This will not affect aliases created manually.