EXT:redirects
In a headless setup the frontend application performs redirects. Whenever
headless mode applies to a request (mixed mode:
Mixed mode and the Accept header), EXT:headless turns the 30x response
TYPO3 would send into a JSON envelope — no feature flag required.
Two kinds of redirects are covered, and they are wired differently:
-
Shortcut pages, mount points and site-base redirects (e.g.
/to/en/) come from core frontend middlewares. EXT:headless replaces them unconditionally, so they are JSON even whenEXT:is not installed:redirects typo3/→cms- frontend/ base- redirect- resolver \FriendsOf TYPO3\ Headless\ Middleware\ Site Base Redirect Resolver typo3/→ disabled and replaced bycms- frontend/ shortcut- and- mountpoint- redirect headless/(cms- frontend/ shortcut- and- mountpoint- redirect \Friends)Of TYPO3\ Headless\ Middleware\ Shortcut And Mount Point Redirect
- Redirect-manager records need
EXT:(redirects composer require typo3/). The corecms- redirects redirecthandlermiddleware stays in place; the JSON envelope is produced by theheadless/event listener (see below), which is registered only whenRedirect Was Hit EXT:is installed.redirects
Outside headless mode the replaced middlewares return the core 30x
response unchanged.
Requests for the initial page type (?type=834,
Initial data (?type=834)) bypass shortcut and mount-point redirect
handling entirely and are resolved downstream instead.
JSON response shape
A matched redirect produces:
{
"redirectUrl": "https://example.com/new-target",
"statusCode": 301
}
For every source the target is first mapped onto the current site's
frontend (Url; hosts the site
does not know, e.g. external URLs, stay unchanged), then run through
prepare: targets on the frontend host come
back as relative paths (/new-), anything else stays absolute.
The HTTP response itself is always 200 — status tells the
frontend which redirect to perform, and the frontend must apply the
usual method semantics itself (301/302 may switch to GET,
307/308 preserve the request method). Its value depends on the
source:
- redirect-manager records: the record's configured target status code;
- shortcut/mount-point and site-base redirects: the HTTP code the core
middleware would have sent (typically
307).
Customising the redirect
The JSON envelope is built by
\Friends,
which listens to the core
\TYPO3\
(identifier headless/). Register your own listener for
the same event after it and replace the response:
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Redirects\Event\RedirectWasHitEvent;
final readonly class TagRedirectsForAnalytics
{
public function __invoke(RedirectWasHitEvent $event): void
{
$response = $event->getResponse();
if (!$response instanceof JsonResponse) {
return;
}
$payload = json_decode((string)$response->getBody(), true);
$separator = str_contains($payload['redirectUrl'], '?') ? '&' : '?';
$payload['redirectUrl'] .= $separator . 'utm_source=redirect';
$event->setResponse(new JsonResponse($payload));
}
}
# Configuration/Services.yaml
services:
Vendor\MyExt\EventListener\TagRedirectsForAnalytics:
tags:
- name: event.listener
identifier: 'myext/redirect/analytics'
after: 'headless/RedirectWasHit'
Page targets carrying Extbase plugin parameters in the typolink
additional segment are rebuilt through the site router by
\Friends (the core
Redirect drops that segment unless "keep query parameters"
is enabled). Override or extend that service via Services.
when you need different target URL resolution.
Short URLs & QR codes (5.x)
The "Short URLs" and "QR Codes" backend modules of EXT: show
source URLs on the TYPO3 host, which is wrong when the public site lives
on the frontend domain. With headless, both modules (and the QR-code/short-URL
fields in redirect records) resolve source URLs against the site's
frontend instead, so copied links and scanned codes land on the
public frontend. No configuration needed beyond frontend; resolution
logic can be replaced by overriding
\Friends via Services..