Skip to content

Wrong settings.php for some multisite cases #7020

@robertgarrigos

Description

@robertgarrigos

Description of the bug

In a multisite set, if multisites are set by subdomain and one subdomain is exactly as the TLD, backdrop serves a wrong settings.php.

In this scenario, each subsite lies in a directory with the same name as the subdomain ($sites['test.domain.test'] = 'test';). If, like in this case, the subdomain is the same as the TLD (test), Backdrop serves the subsite's settings.php file (test.domain.test) when accessing the main site (domain.test).

Steps To Reproduce

Create a multisite set with the specifications described in the description.

Actual behavior

Backdrop serves the subsite's settings.php file when accessing the main site

Expected behavior

Backdrop serves the main settings.php file when accessing the main site.

Additional information

There is an issue related to the same function I propose to fix (#6130), although I believe it will not interfere with this proposed fix:

My proposal is to change this code within the find_conf_path() function:

for ($j = count($server); $j > 0; $j--) {
        $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
        if (isset($sites[$dir]) && file_exists(BACKDROP_ROOT . '/sites/' . $sites[$dir])) {
          $dir = $sites[$dir];
        }
        if (file_exists(BACKDROP_ROOT . '/sites/' . $dir . '/settings.php') || (!$require_settings && file_exists(BACKDROP_ROOT . '/sites/' . $dir))) {
          $conf = './sites/' . $dir;
          return $conf;
        }
      }

with this:

for ($j = count($server); $j > 0; $j--) {
        $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
        if (count($server) > 1 && $j == 1 && strpos($dir, '.') === false) {
          continue;
        }
        if (isset($sites[$dir]) && file_exists(BACKDROP_ROOT . '/sites/' . $sites[$dir])) {
          $dir = $sites[$dir];
        }
        if (file_exists(BACKDROP_ROOT . '/sites/' . $dir . '/settings.php') || (!$require_settings && file_exists(BACKDROP_ROOT . '/sites/' . $dir))) {
          $conf = './sites/' . $dir;
          return $conf;
        }
      }

which include these new lines:

if (count($server) > 1 && $j == 1 && strpos($dir, '.') === false) {
   continue;
 }

With this fix I can access test.domain.test with the right settings.php with apparently no side effect. I will create a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions