Skip to main content
x

Create SEO Friendly / Pretty URLs in Drupal 8

WordPress will allow you to have your lovely search engine friendly URLs at the click of a very simple button (Admin > Settings > Permalinks and then a few options are presented to you) however with Drupal 8 it's a slightly different story, mainly because Drupal 8 can do so much out of the box already that perhaps SEO driven URLs were not at the top of the functionality required.

Out of the box Drupal 8's approach is to allow you to create the URL you want under URL PATH SETTINGS in the node/edit screen, although it provides more control to the author, it can come at the cost of a standard rule sitewide. Have no fear though it's pretty straightforward to set them up, let's walk through it now.

The first step in this is to download the required module, so head over to the Pathauto module page from Drupal.org and download the .tar.gz or .zip.   

From Drupal 8's admin panel, navigate to Extend > Install New Module and you'll be presented with the following form. If you don't have the option to install a new module, take a look here for a resolution

Install New Module - Drupal 8 Click the "Choose File" button and upload the .zip or .tar.gz that you just downloaded and hit install. Once it's uploaded successfully click "Enable Newly Installed Modules", find your module in the list and check the box, then scroll down to enable.

Now we're installed it's time to configure. Navigate to <yourdomain>/admin/config/search/path either directly or Configuration > Search and metadata > URL aliases which will - all being well - resolve you a screen as below.

Drupal 8 - Pathauo Initial Menu

Now we want to set a new ruleset to apply to all nodes of a given content type, to keep content uniform, so click "Patterns" from the sub-navigation and then the "Add Pathautho pattern". In this example we'll create a ruleset for content types of "Article" and "Basic Page", which is achieved with the settings show below.

Drupal 8 Pathauto Ruleset

This will simply use the contents entered into the title field when creating a node of type "Basic Page" or "Article" and use this as the URL, making all characters lowercase, and replacing spaces and special characters with a hyphen. To see the other fields & values available to the ruleset, click "Browser available tokens" which will bring up the following, allowing you access to a variety of options to make your URLs as SEO friendly as you wish.

Drupal 8 Tokens

Once we've saved our ruleset, we now just need to apply the rules to the existing content. This is done by navigating to "Bulk generate" and in this case we're generating aliases just for content, and as no aliases existed before, we can keep it set to the default of generating only for unaliased paths. If we were updating URLs from an existing ruleset, we'd need to change the setting to update.

Drupal 8 - Pauthauto - Autogenerate

Hopefully this will help anyone wanting to get away from the default URLs of /node/11 and more towards /my-awesomely-seo-optimised-drupal-8-page, or perhaps just something more meaningful.

Note: this is a quick and easy guide to getting up and running with SEO friendly URLs through Drupal 8's GUI and not the best practice method of composer require drupal/pathauto as it's assumed if you're using composer to manage dependencies, you're up to speed with pathauto.