In this comprehensive guide, I will walk you through the process of creating vanity URLs in Drupal 8, along with the use of a link shortener for added convenience.
Vanity URLs are customized, easy-to-remember, and user-friendly web addresses that improve the overall user experience and brand recognition.
Get Pathauto Module
Drupal 8 offers a powerful module, Pathauto, that allows you to create vanity URLs effortlessly. Pathauto works by automatically generating URL aliases for various types of content, such as nodes, taxonomy terms, and users, based on configurable patterns.
Visit the Pathauto project page (https://www.drupal.org/project/pathauto) and download the latest version compatible with your Drupal 8 installation.
- Extract the downloaded file and upload the 'pathauto' folder to your 'modules' directory on your server.
- Log in to your Drupal 8 admin dashboard and navigate to Extend (or 'admin/modules').
- Locate the Pathauto module, check the box next to it, and click 'Install.'
Configuring Pathauto
Once the Pathauto module is installed, you can configure it to create vanity URLs for your website:
- Navigate to the Configuration tab in your Drupal 8 admin dashboard.
- Under the 'Search and Metadata' section, click on 'URL aliases.'
- Click on the 'Patterns' tab, where you can create URL alias patterns for different content types, taxonomy terms, and users.
- Define your patterns using tokens, which represent specific data fields. For example, to create a pattern for blog posts, use '[node:title]' as the token, and the URL will be generated based on the title of the post.
- Save your settings by clicking 'Save configuration.'
Creating Custom URL Aliases
If you want to create a custom URL alias for specific content:
- Navigate to the content editing page for the desired node, taxonomy term, or user.
- Scroll down to the 'URL alias' section.
- Uncheck the 'Generate automatic URL alias' box, then enter your custom URL alias in the provided field.
- Save your changes.
Using a Link Shortener with Drupal
In some cases, you might want to use a link shortener to make your vanity URLs even more compact and easy to share.
You can integrate link shortening services like Bitly, Pretty Links, or TinyURL with your Drupal site. Most of these services offer a Drupal module or an API that you can use to automatically shorten your URLs.