Views URL alias

Allows Views to be filtered and sorted by path aliases for content entities.

views_url_alias
1,503 sites
20
drupal.org
Drupal 8 Drupal 9 Drupal 10 Drupal 11

Install

Drupal 11, 10, 9, 8 v3.1.2
composer require 'drupal/views_url_alias:^3.1'

Overview

The Views URL alias module enables Views to be filtered and sorted by URL path aliases. This is particularly useful for websites that use hierarchical URL structures, allowing you to create views that display content from specific sections of your site based on their URL patterns.

The module creates and maintains a separate views_url_alias database table that maps entity IDs to their corresponding URL aliases. This dedicated table provides clean and fast joins between content entity tables and their path aliases, ensuring optimal query performance.

All content entities with URL aliases are supported, including nodes, taxonomy terms, users, and any custom content entity types. The module also integrates seamlessly with the Pathauto module for bulk alias operations.

Features

  • Provides Views relationship for URL aliases on all content entity types
  • Enables filtering Views by URL alias patterns (e.g., show all content under /products/*)
  • Enables sorting Views by URL alias alphabetically
  • Maintains a dedicated views_url_alias database table for fast and efficient joins
  • Automatically synchronizes the alias table when aliases are created, updated, or deleted
  • Full integration with Pathauto module for bulk alias updates
  • Multilingual support with per-language alias tracking
  • Admin interface to rebuild the alias table when needed
  • Supports combining with Views Bulk Operations (VBO) to apply operations to content based on URL paths

Use Cases

Filter content by URL hierarchy

Create a view that displays all nodes with URLs starting with a specific path pattern. For example, show all content under /documentation/* by adding the 'Node URL Alias' relationship and filtering the alias field with 'starts with /documentation/'.

Build section-specific content listings

Display content from specific sections of your website. Add the URL Alias relationship to a content view, then filter by alias containing '/products/' to show only product-related pages.

Sort content alphabetically by URL

Create a sitemap-style view where content is sorted alphabetically by its URL path. Add the URL Alias relationship and sort by the alias field.

Bulk operations on URL-based content sections

Combine with Views Bulk Operations to perform actions on content based on URL patterns. Create a view filtered by alias pattern, add VBO fields, and apply bulk operations like publishing, unpublishing, or changing content ownership.

Multilingual URL filtering

Filter content by language-specific URL aliases. The module tracks aliases per language, allowing you to create views that show content with specific alias patterns in particular languages.

Tips

  • When setting up a view with URL alias filtering, always add the appropriate entity type's URL Alias relationship first (e.g., 'Content URL Alias' for nodes)
  • Check the 'Require this relationship' option if you only want to show content that has URL aliases defined
  • Use the 'starts with' filter operator to match hierarchical URL patterns like /products/*
  • After bulk alias operations with Pathauto, verify the views_url_alias table is current by checking your filtered views
  • The module automatically rebuilds the alias table during installation, so existing aliases are immediately available

Technical Details

Admin Pages 1
Rebuild views alias table /admin/structure/views/settings/alias

This confirmation form allows administrators to rebuild the views_url_alias database table. This operation purges the existing table and repopulates it with all current path aliases from the system. This is typically only needed if URL aliases have been updated outside the normal alias edit form, such as through direct database manipulation or imports.

Hooks 5
hook_ENTITY_TYPE_insert (path_alias)

Inserts a path alias into the views_url_alias table when a new path alias is created.

hook_ENTITY_TYPE_update (path_alias)

Updates the views_url_alias table when a path alias is modified.

hook_ENTITY_TYPE_delete (path_alias)

Removes the corresponding entry from views_url_alias table when a path alias is deleted.

hook_pathauto_alias_alter

Integrates with Pathauto module to save aliases during bulk update operations.

hook_views_data

Provides Views integration by defining the views_url_alias table and creating relationships for all content entity types.

Troubleshooting 4
URL aliases are not appearing in Views filters

The views_url_alias table may be out of sync. Go to Administration > Structure > Views > Settings > Rebuild views alias table and click 'Rebuild table' to repopulate the alias data.

Newly created aliases don't show in Views

Ensure the path alias was created through the normal Drupal interface. If aliases were imported or created via direct database manipulation, you need to rebuild the views_url_alias table.

The URL Alias relationship is not available for my entity type

The module only supports content entities with numeric IDs. Custom entities with string IDs are not supported. Also verify that your entity type has a data table defined.

Performance issues with large numbers of aliases

The module maintains indexed database columns for efficient queries. If you experience slowness, verify the database indexes exist on the views_url_alias table. You may also need to optimize your Views query.