Multi-Site & URL Configuration
The headless setup typically has two domains — one for the API
(TYPO3 backend) and one for the frontend app. This page describes how
EXT: rewrites URLs, handles cookies and routes assets across
the two.
Glossary
| Key | Meaning |
|---|---|
base | Public URL of the TYPO3 site (the API), on its own host. |
frontend | Public URL of your SPA / frontend app. Used by
\Friends
to rewrite links in the JSON response. |
frontend | Public URL of the API as seen by browsers
going through the frontend's reverse proxy
(e.g. https://). Also
used for the sitemap index links
(XML sitemap), api. of
?type=835 and storage proxy URLs
(Storage proxy (asset routing)). |
frontend | Fallback base URL for files of storages
without a base URI or relative base path,
with headless. enabled
(Storage proxy (asset routing)). Per-storage URLs go
in frontend. |
cookie | Domain to scope session cookies to. Read only
with the headless.
feature flag enabled (see below). |
base | Per-environment overrides of any of the above, gated by an expression-language condition. |
Two-domain setup
API on api., frontend on example.. The API site's base
is its own host; set frontend so URLs in the JSON response point at
the frontend. If the frontend server proxies a path such as
https:// to the API, set it as frontend
(see Cross-origin requests (CORS)). Excerpt of the site configuration (dependencies and
languages as usual):
rootPageId: 1
base: https://api.example.com
headless: 1
frontendBase: https://example.com
# Optional: the API as seen through the frontend's proxy
frontendApiProxy: https://example.com/headless
Every typolink and page URL in the JSON response is then rewritten from
https:// to https://.
Multi-language overrides
Each language can override the URL keys independently (excerpt):
languages:
- languageId: 0
title: English
base: /
locale: en_US.UTF-8
frontendBase: https://example.com
- languageId: 1
title: Deutsch
base: /de/
locale: de_DE.UTF-8
frontendBase: https://example.de
Per-environment overrides (baseVariants )
Same site, different dev/stage/prod values (excerpt):
baseVariants:
- base: https://api.dev.example.com
condition: 'applicationContext == "Development"'
frontendBase: https://dev.example.com
frontendApiProxy: https://dev.example.com/headless
- base: https://api.stage.example.com
condition: 'applicationContext == "Staging"'
frontendBase: https://stage.example.com
frontendApiProxy: https://stage.example.com/headless
condition is evaluated by
\TYPO3\
with the site scope — available are the default variables
(application, typo3, date, features) and functions like
getenv; request is not available here.
The first variant whose condition matches wins, and its values are read verbatim: a key missing from the matching variant resolves to an empty string, it does not fall back to the site-level value — repeat every key in every variant.
Cross-origin requests (CORS)
A browser on https:// calling https:// makes a
cross-origin request. There are two ways to handle it:
- Proxy path. The frontend server forwards
https://to the API, andexample. com/ headless/* frontendis set to that path. The browser only talks to its own origin: frontend-session cookies work without a sharedApi Proxy cookie, and no CORS headers are needed. Backend preview still needsDomain cookie, becauseDomain be_is set on the API host at backend login. Prefer this whenever the frontend has a server component.typo_ user - CORS headers. When the browser calls the API host directly, TYPO3 has to
answer with
Access-— the exact origin, notControl- Allow- Origin: https:// example. com *, as soon as cookies are involved — andAccess-, plusControl- Allow- Credentials: true Access-for custom request headers. Form-encoded POSTs are simple requests and need no preflight; requests with custom headers or a JSON body trigger anControl- Allow- Headers OPTIONSpreflight that must be answered as well.
Set the headers in the web server, which also covers redirect envelopes and
error responses. TypoScript covers page responses only (index 10 is taken
by the shipped Content- header, 40 by the Vary header suggested in
Caching):
page.config.additionalHeaders {
20.header = Access-Control-Allow-Origin: https://example.com
30.header = Access-Control-Allow-Credentials: true
}
Storage proxy (asset routing)
With the headless. feature flag, file URLs (originals and
processed files) of local, public storages point at the frontend instead
of the TYPO3 host. Use it when the browser should fetch assets from the
same origin as the SPA.
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['headless.storageProxy'] = true;
The rewrite applies only to frontend requests in headless mode. The base URL of each storage is the first match of:
frontendentry for the storage (Per-storage URLs).File Api By Storage - Base URI with its own host (e.g.
https://): the URL is left unchanged.cdn. example. com/ assets/ - Base URI without a host (e.g.
/assets/) or relative base path (e.g.fileadmin/):frontend+ storage path, e.g.Api Proxy https://.example. com/ headless/ fileadmin/… - Otherwise:
frontend; if empty, the URL is left unchanged.File Api
The files stay where they are: the frontend server has to proxy these paths to the TYPO3 host.
frontend, frontend and the map entries can be a full URL
or only a path:
- A path uses the host of
frontendand starts at the host root:Base /headlessbecomeshttps://, even whenexample. com/ headless frontendhas a path such asBase /shop. - Without a host in
frontend, a path is ignored.Base - Always write another host with its scheme:
cdn.is read as a path.example. com/ x
f: and Image map a URL back to the file only when it starts
with frontend. For URLs from frontend or the map, pass
the file or file reference instead.
Per-storage URLs
To give a storage its own base URL, set frontend in the
site config, keyed by storage uid.
The URL replaces the whole base, and only the file's path inside the storage
is appended. If the CDN serves the files under /fileadmin2/, include that
segment in the URL.
Example: three storages, each holding user_ — uid 1
(fileadmin/, relative), uid 2 (fileadmin2/, relative) and uid 3
(/mnt/, absolute, no base URI):
base: https://api.example.com
frontendBase: https://example.com
frontendApiProxy: https://example.com/headless
frontendFileApi: https://files.example.com/shared
frontendFileApiByStorage:
2: https://cdn2.example.com/fileadmin2
| Storage | File URL | Source |
|---|---|---|
| 1 | https:// | storage path |
| 2 | https:// | frontend |
| 3 | https:// | frontend |
Without frontend, storage 2 would get
https://.
The map resolves like frontend: a matching base variant replaces
the site-level map, and a site language can set its own map:
baseVariants:
- base: https://api.dev.example.com
condition: 'applicationContext == "Development"'
frontendBase: https://dev.example.com
frontendApiProxy: https://dev.example.com/headless
frontendFileApi: https://files.dev.example.com/shared
frontendFileApiByStorage:
2: https://cdn2-dev.example.com/fileadmin2
| Storage | File URL in the Development context |
|---|---|
| 1 | https:// |
| 2 | https:// |
| 3 | https:// |
A matching base variant without frontend disables the
per-storage URLs, just as a variant without frontend empties that
value: storage 2 would then get
https://, not
the production CDN. Repeat the entries you need in each variant, or use
%env placeholders.
Edit this in the YAML files only: the site module does not show the key and drops it from base variants and languages when the site is saved there.
Storage uids are database ids. If they differ between environments, give
each environment its own map in its base variant: the variant replaces the
whole map, keys included. %env placeholders work in the URLs only,
not in the uid keys.
Example: fileadmin2/ has uid 2 in production and uid 5 on the development
system:
frontendFileApiByStorage:
2: https://cdn2.example.com/fileadmin2
baseVariants:
- base: https://api.dev.example.com
condition: 'applicationContext == "Development"'
frontendBase: https://dev.example.com
frontendApiProxy: https://dev.example.com/headless
frontendFileApiByStorage:
5: https://cdn2-dev.example.com/fileadmin2
In the Development context only uid 5 is mapped; uid 2 (a different
storage there, if any) follows the default rules and never gets the
production CDN.
Same uids everywhere, only the URL differs per environment: keep one map and read the URL from an environment variable instead of adding variants:
frontendFileApiByStorage:
2: '%env(CDN2_URL)%'
This only helps where no base variant matches: a matching variant still
needs its own frontend, which can use the same
placeholder.