Problem/Motivation

When the path prefix feature is enabled (domain.path_prefix parameter is TRUE), DomainAliasHooks::domainRequestAlter() calls $this->negotiator->negotiateByPathPrefix($candidates) to disambiguate domains sharing the same hostname. However, negotiateByPathPrefix() can return NULL when no candidate matches the current request path. In that case, $domain is set to NULL, the $domain instanceof DomainInterface check fails, and an error is logged:

Found matching alias %alias for host request %hostname, but no domain with a matching path prefix was found.

This is too harsh: the alias was correctly resolved to a valid target domain — path prefix disambiguation simply couldn't narrow it further. The behavior should gracefully fall back to the alias target domain, consistent with the non-prefix code path which unconditionally sets $domain = $target.

Steps to reproduce

  1. Enable the path prefix feature.
  2. Create two domains sharing a hostname, one with a path prefix and one without.
  3. Create an alias pointing to one of these domains.
  4. Visit a URL that matches the alias but whose path does not match any domain's prefix.
  5. An error is logged instead of resolving to the target domain.

Proposed resolution

Add a null coalescing fallback so that when negotiateByPathPrefix() returns NULL, the alias target domain is used:

$domain = $this->negotiator->negotiateByPathPrefix($candidates) ?? $target;

Issue fork domain-3579069

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review

  • mably committed 8ba318ef on 3.x
    fix: #3579069 Domain alias request alter fails when path prefix...
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.