What are URL aliases?
A URL alias is a clean path for your pages. It converts the node's node/###
path into something more user-friendly
. It determines the portion of the URL after your site's base path.
For example: The URL alias for this page is: documentation/drupal-user-guide/url-aliases
On this page:
Important Information
Aliases are generated automatically by default when content is created. The automatic alias is determined by a pattern that is configured by the framework.
For example:
- News:
news/[title-of-news]
- Faculty & Staff Profiles:
people/[firstname-lastname]
- Basic Pages:
[menu-item-parents]/[title-of-page]
We strongly recommend leaving this option checked to allow pages to automatically generate because it determines the paths to content on your site.
Aliases should be allowed to generate automatically unless absolutely necessary.
This article talks about overriding the default aliases and should be used sparingly for specific use cases.
Automatic Pathing & Redirects
Automatically generated aliases means the paths update automatically.
For example:
- If you create a page titled "
My Page
", the alias it creates ismy-page
. - If you then edit the title of the page to "
My New Page
", the alias will update tomy-new-page
and will automatically redirect any traffic visiting the old alias.
If the alias of a page is overridden and is not set to generate automatically, the alias will remain as my-page
.
Side Note: Aliases need to be unique. If you notice a number at the end of your alias (ie, my-page-0
) it means that something else is already aliased as my-page
(multiple pages created with the same title, same path, etc). You should review what is using the old alias and release it so it can be reused if you want to use it.
Paths
Paths are used by different navigation components of your sites, namely the menu and breadcrumbs.
In Drupal 9, breadcrumbs are determined by the path of a content rather than where it sits in the menu hierarchy. The framework compensates for this change by setting the default pattern for basic pages to emulate the menu hierarchy.
For example:
- If you create a page titled "
My Page
" and placed it under a page called "About Us
" the alias it creates isabout-us/my-page
. - The breadcrumb for this page will appear as "
Home > About Us > My Page
"
If the alias of a page is overridden to custom-alias
, it will:
- remain as that regardless of what you set as the page's title or where you set it in the menu
- your breadcrumbs will appear as "
Home> Custom Alias
" - and if that trail item (
custom-alias
) is not an actual page, the breadcrumb will not generate a link
Reserved Paths
It is also important to note that there are built in paths for standard features that should not be overridden, such as:
news
news/category/*
people
people/category/*
researchers/*
TLDR for leaving URL Aliases to generate automatically unless necessary:
- Consistency and better for SEO
- Ensures the components of the site that relies on paths are working
- Don't have to manage manually
- If the information above is confusing, best to leave things default
Creating a URL alias for a page
You can create an alias one of two ways:
- In Page: When creating or editing a basic page
- In Configuration: Through the URL Aliases option from the "Configuration" section of the site
In Page
- Create a page or Edit the page you wish to create an alias for
- In the URL Alias setting on the left, uncheck Generate automatic URL alias
- Warning: Please read the important note above to understand how overriding automatically generated aliases will affect your site.
- In the field, provide the custom alias you wish to set.
- Tip: Please review the best practices below to ensure you are providing a valid alias.
- Save
In Configuration
- Go to Manage > Configuration
- Under Search and metadata, Click URL aliases
- Click Add Alias button
- Provide the system path
- This is the existing path you wish to alias. For example: /node/28, /node/69, /node/420, etc
- Provide the URL alias
- Tip: Please review the best practices below to ensure you are providing a valid alias.
- Save
Updating a URL alias
If you want to reuse an alias for a different path, you would need to update it.
- Go to Manage > Configuration
- Under Search and metadata, Click URL aliases
- Look for the existing alias in the list and click Edit
- Tip: Use the filter to find it faster
- Change the system path to the new location. (Change the node id to the new page you would like to set)
- Tip: An easy way to find out the node id of a page is look at the url at the bottom of your browser when you hover over the "edit" tab of the page.
Deleting URL alias
- Go to Manage > Configuration
- Under Search and metadata, Click URL aliases
- Look for the existing alias in the list
- Tip: Use the filter to find it faster
- In the Operations columns, click the down arrow next to the edit button and click Delete
- You will be taken to a confirmation page. Click Delete.
- Warning: As with all deletion in Drupal, deletion of aliases is permanent and cannot be undone.
Best Practices
- Aliases should be allowed to generate automatically unless absolutely necessary.
- Aliases should never contain a slash at the start or end
- Aliases should never contain a space
- Aliases should only contain lower case letters, numbers and hyphens
- Aliases must be unique
- Aliases should not start with any subsite name followed by a slash
- Aliases should only ever be relative paths