Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module enhances the Redirect module by allowing you to create redirects using regular expressions instead of just exact path matching. This enables more flexible redirection rules, such as pointing old blog post URLs to an archive page or redirecting user profile URLs. Regex redirects are identified by source paths starting with "regex:".

This module extends the Redirect module to support regex pattern matching in addition to exact path matching using the redirect entities.

Features

  • Extends RedirectRepository: The RedirectRegexRepository extends the RedirectRepository class
  • Service Override: Uses a service decorator to override the redirect.repository service
  • Convention-Based: Regex redirects are identified by source paths starting with regex:
  • Backward Compatibility: All existing redirect functionality continues to work unchanged
  • Compatible with GraphQL through the Redirect module

Examples

Source Path Redirect Target Description blog/\d+/.* /blog/archive Redirect old blog URLs to archive user/\d+/profile /user/profile Redirect user profile URLs page/old/([0-9a-z]+) /page/new-page Redirect old page URLs with alphanumeric IDs legacy/(\d+) /migrated/$1 Redirect legacy URLs to an equivalent modern URL, substituting the ID legacy/(?'id'\d+) /migrated/$id Redirect legacy URLs to an equivalent modern URL, substituting the ID through its named reference

Query:

query MyQuery {
  route(path: "/user/123/profile") {
    ... on RouteRedirect {
      __typename
      internal
      redirect
      status
      url
    }
  }
}

Response:

{
  "data": {
    "route": {
      "__typename": "RouteRedirect",
      "internal": true,
      "redirect": true,
      "status": 301,
      "url": "/node/1"
    }
  }
}

Creating Regex Redirects

To create a regex redirect:

  1. Go to /admin/config/search/redirect/add
  2. Set the From field to: your-pattern
    • Example: user/\d+/profile
  3. Set the To field to the redirect target
  4. Tick the Regular expression checkbox to enable regex redirects
  5. Save the redirect

Important Notes:

  • Do NOT include a leading slash in the regex pattern (e.g., use user/\d+/profile, not /user/\d+/profile)
  • The redirect system automatically strips leading slashes before matching
  • For redirects from existing routes, enable "Allow redirects from aliases" in redirect settings
  • Multilingual Support: Patterns are tested against both the current path and the path with language prefix (e.g., user/123/profile and en/user/123/profile)
  • Patterns are matched against the entire path, and is case-insensitive.
  • Internally, the Redirect source will have a regex: prefix.

Dependencies

  • Redirect module (>=1.12) — provides the redirect entities and admin interface

Similar projects

Activity

Total releases
8
First release
Sep 2025
Latest release
2 weeks ago
Releases (12 mo)
8 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Release date
1.0.0-alpha7 Pre-release Jul 2, 2026
1.0.0-alpha6 Pre-release May 27, 2026
1.0.0-alpha5 Pre-release Sep 25, 2025
1.0.0-alpha4 Pre-release Sep 24, 2025
1.0.0-alpha3 Pre-release Sep 24, 2025
1.0.0-alpha2 Pre-release Sep 24, 2025
1.0.0-alpha1 Pre-release Sep 24, 2025
1.x-dev Dev Sep 24, 2025