Creating user-friendly and SEO-optimized URL structures is crucial for improving your website's search engine rankings and user experience. Drupal 9, a powerful content management system, offers several options to create custom URL patterns that enhance the site's overall structure. In this blog post, we'll show you how to create URL aliases based on parent menu links in Drupal 9 using the Pathauto module. This approach ensures that your website has a coherent and easy-to-navigate URL structure, which is essential for SEO.
Before we begin, make sure you have the following:
Follow these steps to create URL aliases based on the parent menu link and the node title.
If you haven't already, download the Pathauto module from the Drupal project page and install it on your Drupal site.
composer require drupal/pathauto
You can enable the module using the Drupal UI or by running the following Drush command:
Navigate to Configuration > Search and metadata > URL aliases in the Drupal admin menu (/admin/config/search/path). Click on the "Patterns" tab.
Click on "Add Pathauto pattern." Choose the content type for which you want to create the URL alias pattern. Set the pattern to use the parent menu link and the node title, like this:
This pattern will create aliases based on the parent menu link's URL and append the node title at the end. The
join-path function will concatenate the parent menu items' paths. Save the new pattern.
If you want to generate aliases for existing content, go back to the main URL aliases page (Configuration > Search and metadata > URL aliases) and click on the "Bulk generate" tab. Select the content types you want to generate aliases for and click on "Update."