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 Singapore: It’s A Wind Up For 2024

DrupalCon Singapore Wind Up DrupalCon Singapore OpenSense Labs

OpenSense Labs team attended the DrupalCon Singapore 2024 and it was a wonderful and valuable experience, especially since it…

Drupal SDC: Advantages of Single Directory Components 

Advantages of Drupal SDC OpenSense Labs

What if one solution could organize website UI components, make them easy to reuse in different projects, ensure consistency…

Drupal 11 Upgrade: Checklist For Drupal 7 to 11 Migration 

Drupal 11 Upgrade Checklist OpenSense Labs

Drupal 10 was released in December 2022, and Drupal 11 upgrade arrived in just a year and a half. Drupal 11 came out early,…