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
- Enable the path prefix feature.
- Create two domains sharing a hostname, one with a path prefix and one without.
- Create an alias pointing to one of these domains.
- Visit a URL that matches the alias but whose path does not match any domain's prefix.
- 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
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
Comment #3
mably commentedComment #5
mably commented