Skip to content

Nav entry links across sites lose their domain despite select_across_sites #15237

Description

@marcorieser

Bug description

On a multi-site install with sites on different domains, a nav item linking to an entry on another site renders {{ url }} with the scheme and host stripped, so the browser resolves it against the current site and 404s.

A nav on a Museum site at https://museum.test, linking to the Foundation site's projects entry, renders <a href="/projects"> instead of <a href="https://foundation.test/projects">. {{ permalink }} on the same item is correct, so only {{ url }} is affected.

{{ url }} resolves to Entry::url() and therefore Routable::urlWithoutRedirect(), where absoluteUrlWithoutRedirect() builds the correct host from the target entry's site and URL::makeRelative() then drops it unconditionally:

publicfunctionurlWithoutRedirect()
{
if (! $url = $this->absoluteUrlWithoutRedirect()) {
returnnull;
}
returnURL::makeRelative($url);
}

This looks like the nav equivalent of #12694, which fixed the same thing for Bard entry links by returning absoluteUrl() when select_across_sites is enabled. Navs have that setting too, but weren't covered.

It also affects is_current and is_parent, which Structure::toArray() derives from that same host-less URL, so a cross-site item can be flagged active when the two sites happen to share a path.

How to reproduce

  1. Two sites on different domains:
museum:
url: 'https://museum.test/'foundation:
url: 'https://foundation.test/'
  1. A routable pages collection on both sites, with a projects entry in foundation.
  2. A main nav with select_across_sites: true.
  3. In the museum tree, add an item linking via entry (not via URL) to that foundation entry.
  4. Render it on the museum site:
{{ nav:main }}{{ title }} — url: {{ url }} — permalink: {{ permalink }}{{ /nav:main }}

Expected url: https://foundation.test/projects

Actual url: /projects (permalink is correct)

Environment

EnvironmentLaravel Version: 13.26.1PHP Version: 8.5.8Composer Version: 2.10.2Environment: localDebug Mode: ENABLEDMaintenance Mode: OFFTimezone: UTCLocale: enCacheConfig: NOT CACHEDEvents: NOT CACHEDRoutes: NOT CACHEDViews: CACHEDDriversBroadcasting: logCache: fileDatabase: sqliteLogs: stack / singleMail: logQueue: syncSession: fileStoragepublic/storage: LINKEDLivewireLivewire: v4.4.1StatamicAddons: 10License Key: Not setSites: 3Stache Watcher: Enabled (auto)Static Caching: DisabledVersion: 6.28.0 PROStatamic Addonsaryehraber/statamic-captcha: 1.17.0jacksleight/statamic-bard-mutator: 3.0.5jacksleight/statamic-distill: 1.2.0marcorieser/statamic-livewire: 5.3.1statamic-rad-pack/typesense: 3.2.2statamic/podcast-categories: 2.0.0statamic/seo-pro: 7.13.2transformstudios/events: dev-fix/calendar-day-timezone-mismatchtransformstudios/prime: dev-releasetransformstudios/review: 6.0.0

Installation

Fresh statamic/statamic site via CLI

Additional details

Reproduced on 6.28.0; the same code path is on 5.x. Worth noting Structure::toArray() is shared by {{ nav }} and {{ structure }}, but select_across_sites only exists on navs.

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