Redirect

Provides a unified redirection API that allows users to redirect from old URLs to new URLs, including automatic redirect creation when URL aliases change.

redirect
266,142 sites
195
drupal.org

Install

Drupal 11, 10 v8.x-1.12
composer require 'drupal/redirect:8.x-1.12'
Drupal 9 v8.x-1.11
composer require 'drupal/redirect:8.x-1.11'

Overview

The Redirect module provides a comprehensive URL redirection solution for Drupal sites. It allows site administrators to create and manage redirects from old URLs to new URLs, helping maintain SEO value and user experience when content moves or URLs change.

The module provides a unified redirection API that replaces and consolidates functionality previously offered by path_redirect and globalredirect modules. It intercepts incoming requests and automatically redirects visitors to the correct destination based on configured redirect rules.

Key capabilities include support for various HTTP redirect status codes (301, 302, 303, etc.), automatic redirect creation when URL aliases are changed, query string passthrough, language-specific redirects, and integration with the node editing interface to display and manage redirects directly from content forms.

The module also includes route normalization features that enforce clean and canonical URLs by redirecting to aliases if they exist, removing trailing slashes, and ensuring proper language prefixes.

Features

  • Create and manage URL redirects from old paths to new destinations with various HTTP status codes (300-307)
  • Automatically create redirects when URL aliases are changed, preserving SEO value
  • Support for language-specific redirects that take precedence over global redirects
  • Query string passthrough that retains URL parameters through redirects
  • Route normalization to enforce clean and canonical URLs across the site
  • Integration with node edit forms showing existing redirects to content
  • Views-based administration interface with filtering and bulk operations
  • Redirect loop detection and prevention with logging
  • Enable/disable individual redirects without deletion
  • Chained redirect resolution for complex redirect scenarios
  • Path prefix caching for improved performance on sites with many redirects
  • Migration support from Drupal 6 and 7 path_redirect data

Use Cases

Site Migration with URL Structure Changes

When migrating content to a new URL structure, create 301 redirects from old paths to new locations. The module ensures search engine rankings are preserved and users following old links reach the correct content.

Content Consolidation

When merging multiple pages into one, create redirects from the removed pages to the consolidated page. This maintains link equity and prevents 404 errors.

Fixing Common Typos

Create redirects for commonly mistyped URLs (e.g., /contct to /contact) to improve user experience without creating duplicate content.

Domain Consolidation

Using the Redirect Domain submodule, redirect traffic from old domains (old-site.com) to the new domain (new-site.com) while preserving path structure.

Tracking and Fixing Broken Links

Enable the Redirect 404 submodule to automatically log 404 errors. Review the 'Fix 404 pages' report to identify frequently requested missing pages and create appropriate redirects.

URL Alias Changes

Enable automatic redirect creation so that when content URL aliases are updated, redirects are automatically created from the old alias to the new one.

Vanity URLs and Marketing Campaigns

Create short, memorable redirects for marketing campaigns (e.g., /sale to /products/summer-sale-2024) that can be easily shared in print or verbal communications.

Tips

  • Use 301 (Moved Permanently) for permanent URL changes to preserve SEO value; use 302 (Found) for temporary redirects
  • Enable the Redirect 404 submodule to proactively identify and fix broken links on your site
  • Language-specific redirects always take precedence over 'All languages' redirects - useful for multilingual sites
  • The 'URL redirects' tab on node edit forms provides quick access to manage redirects without leaving the content editing workflow
  • When using drush, you can export/import redirects as part of your configuration management workflow
  • Review the route normalizer settings to ensure they match your site's URL structure requirements
  • For high-traffic sites, consider adjusting the redirect_prefix_list_max setting (default 100) in settings.php

Technical Details

Admin Pages 4
URL redirects /admin/config/search/redirect

Main administration page for viewing, filtering, and managing all URL redirects. Displays a table with source path, destination, enabled status, status code, language, creation date, and operations. Supports bulk delete operations via Views Bulk Operations.

Add URL redirect /admin/config/search/redirect/add

Form for creating a new URL redirect. Allows specifying the source path, destination URL, redirect status code, and language settings.

Edit URL redirect /admin/config/search/redirect/edit/{redirect}

Form for editing an existing redirect with the same fields as the add form.

Settings /admin/config/search/redirect/settings

Global configuration options for the Redirect module, including automatic redirect creation, query string handling, and route normalization settings.

Permissions 2
Administer individual URL redirections

Allows users to create, edit, and delete URL redirects

Administer global URL redirection settings

Allows users to configure global redirect settings like automatic redirect creation and route normalization

Hooks 6
hook_redirect_response_alter

Alter the redirect response before it is delivered to the user. Can modify headers, status code, or even change the destination URL.

hook_redirect_presave

Act on a redirect before it is saved

hook_redirect_insert

Act on a redirect after it has been created

hook_redirect_update

Act on a redirect after it has been updated

hook_redirect_delete

Act on a redirect after it has been deleted

hook_redirect_load

Act on redirects after they have been loaded

Troubleshooting 6
Redirect loop detected (503 error)

Check for circular redirects where A→B→A. The module logs these to watchdog. Review your redirects to break the loop chain.

Redirect not working on admin pages

Check if 'Ignore redirections on admin paths' is enabled in settings. This is intentional to prevent lockouts.

Query parameters being lost during redirect

Ensure 'Retain query string through redirect' is enabled in settings. Note that query parameters defined in the redirect destination take precedence.

Automatic redirects not being created when aliases change

Verify 'Automatically create redirects when URL aliases are changed' is enabled in settings. The Path module must also be enabled.

404 errors not appearing in Fix 404 pages

Check if the path matches any patterns in 'Pages to ignore' setting. Also verify the redirect_404 submodule is enabled.

Performance issues with many redirects

The module uses prefix caching to optimize lookups. Ensure cache is working properly. Consider the redirect_use_prefix_list setting in settings.php.

Security Notes 4
  • Enable 'Check access to the redirected page' setting if you have protected content to prevent URL discovery through redirect probing
  • Be cautious when creating redirects to external URLs - verify destinations are legitimate
  • The module requires 'administer redirects' permission to create/edit redirects, and 'administer redirect settings' for global configuration changes
  • Redirect sources are validated to prevent creating redirects from the front page, which could cause site lockout