Score:0

Drupal in subdirectory behind reverse proxy

pl flag

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.

vidarlo avatar
ar flag
This may [be a better fit at the Drupal SE](https://drupal.stackexchange.com).
Score:0
pl flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.