atoolo / redirect-bundle
A Symfony bundle that resolves redirects, aliases and short URLs from a compiled matcher
Package info
github.com/sitepark/atoolo-redirect-bundle
Type:symfony-bundle
pkg:composer/atoolo/redirect-bundle
Requires
- php: >=8.1 <8.6.0
- atoolo/resource-bundle: ^1.10
- psr/log: ^2.0 || ^3.0
- symfony/config: ^6.3 || ^7.0
- symfony/console: ^6.3 || ^7.0
- symfony/dependency-injection: ^6.3 || ^7.0
- symfony/event-dispatcher: ^6.3 || ^7.0
- symfony/framework-bundle: ^6.3 || ^7.1
- symfony/http-foundation: ^6.3 || ^7.0
- symfony/http-kernel: ^6.3 || ^7.0
- symfony/messenger: ^6.3 || ^7.4.7
- symfony/routing: ^6.3 || ^7.0
Requires (Dev)
- atoolo/deployment-bundle: dev-main
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- infection/infection: ^0.27.6
- overtrue/phplint: ^9.7.1
- phpcompatibility/php-compatibility: ^9.3
- phpunit/phpunit: ^10.5.64
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
Suggests
- atoolo/deployment-bundle: Builds the redirect cache at the deployment (needs ContextAwareDeploymentExecutable)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 16:02:52 UTC
README
Symfony bundle that resolves redirects, aliases and short URLs of a channel.
The rules are compiled into a Symfony CompiledUrlMatcher, so matching takes
a few microseconds whether there are 1,000 or 50,000 rules (see
bin/benchmark.php).
Rule file
The CMS publishes one rule file per site (publication type CONFIG) to
<RESOURCE_ROOT>/configs/redirect-rules.php. The rules of a microsite live in
configs/<micrositePath>/redirect-rules.php, next to its other configuration
such as manifest.php (e.g. configs/microsite/x/redirect-rules.php for the
microsite path /microsite/x). The file returns a list:
<?php return [ ['source' => '/kurz', 'type' => 'exact', 'target' => '/seite/a.html', 'status' => 'alias', 'group' => 'campaign'], ['source' => '/alt', 'type' => 'prefix', 'target' => '/neu/{rest}', 'status' => 301], ];
| key | meaning |
|---|---|
source |
path of the request; compared case-insensitively, a trailing slash is ignored |
type |
exact, or prefix (the path itself and everything below it) |
target |
target path or URL; {rest} is replaced by the remaining path of a prefix |
status |
alias (internal forward) or the redirect status 301, 302, 307, 308 |
group |
optional, free text for the caller |
The query string of the request is appended to the target of a redirect. The
first of two rules with the same source wins; the duplicate is logged.
Invalid entries are logged and skipped. The bundle does not check time
limits: the file only contains the currently valid rules. Other files below
configs are ignored.
Cache
The compiled matcher is never built during a request. It is stored below
var/redirects/<anchor>/[<micrositePath>/] (parameter
atoolo_redirect.cache_dir) as an immutable version file plus a pointer file
current. Without a cache the matcher returns no result; it logs an error only
if rule files exist.
Usage
$match = $redirectMatcher->matchRequest($request); // ?RedirectMatch // $match->target, $match->status (null = alias), $match->isAlias(), $match->group
The microsite is taken from the server variable ATOOLO_MICROSITE_PATH.
Building the cache
The cache of a channel is rebuilt
- by the worker when the CMS reports a changed rule file (publication type
CONFIG, path[/<micrositePath>]/redirects/<name>.php) and when a worker starts; - by the deployment (
deployment:deploy,feds:warm-up,/api/admin/warm-up) ifatoolo/deployment-bundlewithContextAwareDeploymentExecutableis installed. The context keyresource_rootnames the roots to build, otherwise the known ones are used; - by
cache:clear/cache:warmup; - by hand:
bin/console redirect:cache:build [--root=<RESOURCE_ROOT>].
The known roots are remembered in var/redirects/roots.json. Old versions of
the compiled file are deleted after keep_versions_seconds (default 3600).