A flexible Neos CMS package for configuring domain and path-based HTTP redirects using plain strings or regex patterns.
- Domain-based redirects: Redirect entire domains to new locations
- Regex support: Use regex patterns for both domain matching and path transformations
- Path transformation rules: Define multiple rules per domain with regex patterns
- Custom status codes: Configure individual status codes (301, 302, 307, etc.) per redirect
- Capture group support: Use regex capture groups (
$1,$2, etc.) in replacements - Flexible configuration: Works with plain domain strings or complex regex patterns
- HTTP Middleware: Runs after Neos redirect middleware for optimal performance
Install via Composer:
composer require kaufmanndigital/domainredirectionAdd your redirect configuration to your Settings.yaml:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'old-domain.com'
target: 'https://new-domain.com'
statusCode: 301Redirect an entire domain to a new location:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'old-domain.com'
target: 'https://new-domain.com'
statusCode: 301Result:
old-domain.com→https://new-domain.comold-domain.com/any/path→https://new-domain.com
Use regex to preserve and transform the path:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'old-domain.com/(.*)$'
target: 'https://new-domain.com/$1'
statusCode: 301Result:
old-domain.com/about→https://new-domain.com/aboutold-domain.com/contact/form→https://new-domain.com/contact/form
Redirect a subdomain to a specific path on the main domain:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'blog.example.com'
target: 'https://example.com/blog'
statusCode: 307Result:
blog.example.com→https://example.com/blogblog.example.com/article→https://example.com/blog
Redirect a subdomain and append the path to a specific location:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'karriere.example.com/(.*)$'
target: 'https://example.com/careers#$1'
statusCode: 307Result:
karriere.example.com/jobs→https://example.com/careers#jobskarriere.example.com/apply/form→https://example.com/careers#apply/form
Define multiple rules for different path patterns on the same domain:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'example.com'
target: 'https://new-example.com'
statusCode: 301
rules:
- pattern: '^/old-section/(.*)$'
replacement: '/new-section/$1'
statusCode: 301
- pattern: '^/legacy/(.*)$'
replacement: '/modern/$1'
statusCode: 302Result:
example.com/old-section/page→https://new-example.com/new-section/pageexample.com/legacy/content→https://new-example.com/modern/content(302)example.com/other→https://new-example.com(fallback)
Configure multiple domain redirects in the same configuration:
KaufmannDigital:
DomainRedirection:
redirects:
- domainPattern: 'old-site.com'
target: 'https://new-site.com'
statusCode: 301
- domainPattern: 'beta.example.com'
target: 'https://example.com/beta'
statusCode: 307
rules:
- pattern: '^/test/(.*)$'
replacement: '/testing/$1'
statusCode: 302-
domainPattern(required): Domain to match. Can be:- Plain string:
'example.com' - Regex pattern:
'example.com/(.*)$'
- Plain string:
-
target(required): Target URL to redirect to -
statusCode(optional, default: 301): HTTP status code for the redirect301- Permanent redirect302- Temporary redirect307- Temporary redirect (preserves HTTP method)308- Permanent redirect (preserves HTTP method)
-
pattern(optional): Regex pattern for path transformation (alternative to using regex indomainPattern) -
rules(optional): Array of path-specific rules
pattern(required): Regex pattern to match against the pathreplacement(required): Replacement string (can include capture groups like$1,$2)statusCode(optional): Override status code for this specific rule
- The middleware checks each configured redirect in order
- If
domainPatternmatches (either as plain string or regex):- First, it checks if any
rulesmatch the current path - If a rule matches, it applies the rule's transformation
- If no rule matches, it uses the default
target
- First, it checks if any
- The middleware runs after the Neos redirect middleware
- If no redirect matches, the request continues to the next middleware
This package is licensed under the MIT License.
KaufmannDigital GmbH - https://www.kaufmann.digital