Running TYPO3 in a subdirectory

At work we're running a couple of composer-based TYPO3 v11 instances in a subdirectory instead of the root path of domains, e.g. https://example.org/info/ instead of https://example.org/. We do this because the main web application runs on /, while /info/ serves editor-editable content.

The setup consists of 2 servers/containers. One serves the main web application on https://example.org/ and proxies all /info/ requests to the second web server. The second web server delivers a TYPO3 instance.

It's more complicated than the average reverse proxy setup. In production, the initial proxying is done by AWS Cloudfront - and that does not support stripping paths when proxying.

Main webserver

Relevant Apache 2.4 site configuration:

<VirtualHost *:80>
    ServerName example.org
    [...]
    ProxyPass        "/info/" "http://typo3.example.org/info/"
    ProxyPassReverse "/info/" "http://typo3.example.org/info/"
</VirtualHost>

TYPO3 webserver

Apache site configuration:

<VirtualHost *:80>
    ServerName example.org
    ServerAlias typo3.example.org
    UseCanonicalName On
 
    [standard typo3 configuration follows]
 
    <IfModule mod_rewrite.c>
        # Reverse Proxy configuration in Terraform does not allow to
        # proxy "/info/" to "/" - it maps "/info/" to "/info/"
        # So we need to remove that.
        # Also requires REQUEST_URI modification in AdditionalConfiguration.php
        RewriteRule "^info/(.*)" "$1"
    </IfModule>
</VirtualHost>

TYPO3's site configuration is configured to have /info/ in the base path:

config/sites/example/config.yaml
base: 'https://example.org/info/'

TYPO3 also needs to know that it's running in a reverse proxy setup:

public/typo3conf/LocalConfiguration.php
<?php
return [
    //[...]
    'SYS' => [
        //[...]
        'reverseProxyHeaderMultiValue' => 'first',
        'reverseProxyIP' => '172.17.190.*,127.0.0.1',
        'reverseProxyPrefix' => '/info',
        'reverseProxySSL' => '172.17.190.',
    ]
];

And at last, we rewrite the request URI variable used by TYPO3:

public/typo3conf/AdditionalConfiguration.php
<?php
//manually fix the URL that TYPO3 uses as base for route detection
// needed because cloudfront/terraform config does not allow proxy
// "/info/" to "/"
// .htaccess entry is needed as well.
if (isset($_SERVER['REQUEST_URI'])){
    $_SERVER['REQUEST_URI'] = preg_replace('#^/info/#', '/', $_SERVER['REQUEST_URI']);
}

Local setup

The setup above requires two servers/containers, which is fine for production. Local development setup is a bit simpler; we use one container with two different domains:

example-proxy.test

Used for the main webserver.

We access TYPO3 frontend at http://example-proxy.test/info/, and the backend at http://example-proxy.test/info/typo3/.

It proxies to http://example.test/info/.

example.test

Runs TYPO3

Written by Christian Weiske.

Comments? Please send an e-mail.