0

On my public-facing host, Apache works as reverse proxy to a non-public host, where a Drupal 9 instance is symlinked under the web root. Drupal answers to requests, but it outputs any local links with the symlink name included. Apparently because the PHP request variable $_SERVER['SCRIPT_NAME'] includes it.

How do I tell Drupal about it's "actual" base path?

The details

Public host config:

<Location "/"> ProxyPreserveHost on ProxyPassReverse "https://otherserver/webb/" </Location> 

On otherserver, my domain example.com is a virtual host with its root in /var/www/sites/example.com/html. There is this symlink webb, pointing to the Drupal location:

/var/www/sites/example.com/html/webb -> /var/www/sites/example.com/html/drupal8/web/ 

Drupal responds, but in the response HTML, a link that should be to /about is instead to /webb/about, and the same goes for assets, etc.

If I echo $_SERVER['SCRIPT_NAME'], I get /webb/index.php.

1

1 Answer 1

0

I fixed this by altering REQUEST_URI and SCRIPT_NAME in settings.php:

$trim_path = '/webb'; if (isset($GLOBALS['request'])) { $request = $GLOBALS['request']; if ($request->server->get('SCRIPT_NAME') == "$trim_path/index.php") { $request->server->set('SCRIPT_NAME', '/index.php'); $request_uri = substr($request->server->get('REQUEST_URI'), strlen($trim_path)); $request->server->set('REQUEST_URI', $request_uri); } } 

Kudos to lightsurge for the earliest mention of this idea that I could find.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.