Skip to main content
Image
1920x600-02.jpg

How To Add URL Patterns Using PathAuto

article publisher

Raman

Drupal

“The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias” - Drupal.org

Considered as one of the best practices for SEO, it is essential that your Uniform Resource Locator aka URL assists any layman in locating your resources easily. A crucial element when preparing your website for SEO or better UX, it is often overlooked by organizations. URLs play a very crucial role in the ranking of your website. 

Modern search engines give preference to URLs which are:

  • Short and crisp
  • Legible
  • No request parameters
  • No URL unsafe characters
  • Important keywords

By default, Drupal assigns URL of the format node/[node:nid] to content items, taxonomy/term/[term:tid] to taxonomy terms, and user/[user:uid] to the users. URL aliases can be added either while creating the content items or by adding URL alias manually for each system Path using

Manage → Configuration → Search and metadata → URL aliases.

This built-in functionality works due to the Path module which comes with Drupal core.

Often you will come across one of the two issues when following URL practices:

  • Content items are added without adding proper URL alias. 
  • Content publisher (who write and publish content) lacks proper knowledge of SEO and more importantly SEO friendly URLs.

Pre-Requisites

It requires the following modules to be pre-installed and enabled:

  1. Token
  2. CTools  (for Drupal 8 onwards)
     

Downloading and Installing Pathauto

It can be downloaded and installed just like any other module in Drupal. Any of the four methods below can be followed to install Pathauto.

  • Using UI
  1. Navigate to Manage → Extend → Install new module and enter the .tar.gz or .zip URL of the module and hit Install
    An image showing the installing of PathAuto
    Installing PathAuto using FTP
  2. Once the downloader and installer are finished downloading, click on “Enable newly added modules”.
    Image showing the successful installation message of Pathauto
    Wait for the installer to finish downloading and installing
  3. Find Pathauto in the list of modules, select it and click on Install.
    Image showing enabling of Pathauto module
    Enabling the module

    For rest of the methods, first, navigate to the root directory of your Drupal site, $ cd /var/www/html/drupal-8.4.4

  • Using Composer
  1. Add Pathauto package using composer 

    $ composer require "drupal/pathauto"
     
  2. Enable the module by navigating to Manage Extend, selecting Pathauto and click Install
     
  • Using Drush

Download and enable the module using Drush
$ drush dl pathauto
$ drush en pathauto -y

 

  • Using Drupal Console

Download and install the module using Drupal Console

$ drupal module:download pathauto
$ drupal module:install pathauto

Adding URL Patterns

Navigate to Manage → Configuration → Search and metadata, select the 'Patterns' tab and click on Add Pathauto pattern.

Adding Pathauto pattern; an example is shown in the image "article/[node:author]/[node:title]"
Adding the Path pattern
  1. Select Pattern type to Content
     
  2. Give a suitable Path pattern, eg: article/[node:author]/[node:title]. Tokens allow the creation of dynamic URL patterns, a full list can be viewed using Browse available tokens.
     
  3. Provide a Label to this URL pattern, check Enabled and hit Save.
     
  4. Similarly, URL patterns can be created for other content types, taxonomies and users.
Image showing the examples of Pathauto patterns like City/[term:name]
Few examples of Pathauto patterns


Creating Bulk URL Aliases

This feature of Pathauto allows creating URL aliases in bulk for already existing content, taxonomies, and users.

Generating URL aliases in bulk by selecting the "generate a URL alias for un-alaiased path only"
Generating URL aliases in bulk

 

  1. Navigate to Manage → Configuration → Search and metadata and select the Bulk generate tab.
     
  2. Select the entities for which you wish to generate URL aliases.
     
  3. Select the appropriate paths for which URL aliases to generate.


Deleting Bulk URL Aliases

Similar to adding URL aliases in bulk, the module also allows deleting them. However, this is not recommended on a live site.

 Deleting URL aliases in bulk by selecting "All alias" in Choose Aliases to delete; Selecting the "only delete automatically generated alias" in Delete options
Deleting URL aliases in bulk 
  1. Navigate to Manage → Configuration → Search and metadata and select the Delete aliases tab
     
  2. Select the entities for which you want to delete URL aliases
     
  3. Check Only delete automatically generated aliases to prevent deletion of manually created aliases and click on Delete aliases now


Tweaking Pathauto

Default settings of Pathauto are optimized for SEO friendly URLs and should suffice the needs of most of the users. Few of the settings that may be tweaked as per requirements:

Settings Description Default Value
Separator Character  
The character used to separate words
 
-
 
Maximum alias length
 
 
The maximum length of URL alias generated
 
100
 
Maximum component length
 
 
The maximum length of individual components of alias, such as [node:title]
 
100
Strings to remove  
Words to exclude from URL alias
 
 
a, an, as, at, before, but, by, for, from, is, in, into, like, of, off, on, onto, per, since, than, the, this, that, to, up, via, with
 
 
Punctuations
 
 
Special characters like a comma (,), semicolon (;), etc
 
 
Remove
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Refer {your-drupal-site}/admin/config/search/path/settings for more settings.


To Sum Up

The module helps to automate the process of creating SEO friendly URL aliases, thereby improving the ranking index of your website. You may want to redirect your existing “system paths” to the newly created URL aliases. Redirect module can be used along with Pathauto to get the desired result.

In case of any query feel free to comment below. 

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

DrupalCon Barcelona: 2024 Wrap-Up From Europe

DrupalCon-Barcelona-Wrap-Up-Blog

DrupalCon, the main conference focusing on the digital experience platform Drupal, took place this year in Barcelona, Spain, from…

Drupal 11: Nine Must-Know Features

9-Amazing-Drupal-11-Features-OpenSense-Labs

Drupal is a free, open-source platform for creating and managing websites, digital directories, and additional online content. It has a…

Migrate To Your Search Engine Optimized Drupal Website

abc

Website migration not only sounds complex but puts at stake the very existence of your website. While SEO is one of the many factors…