Search by

atoolo / redirect-bundle

sitepark

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

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main / 1.x-dev 2026-12-03 16:02 UTC

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) if atoolo/deployment-bundle with ContextAwareDeploymentExecutable is installed. The context key resource_root names 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).