Skip to content

[5.x] Fix canonical URL handling for subdomain routing - #258

Merged
MrPunyapal merged 4 commits into
pestphp:5.xfrom
hafezdivandari:5.x-fix-canonical-url
Sep 14, 2026
Merged

MrPunyapal merged 4 commits into
pestphp:5.xfrom
hafezdivandari:5.x-fix-canonical-url

Conversation

@hafezdivandari

@hafezdivandari hafezdivandari commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Rework of #224 for 5.x

Why

Pest's browser plugin binds its in-process HTTP server to 127.0.0.1:<port> and, before this fix, pinned Laravel's URL generation to that address,app.url, url(), route() and asset() all resolved to http://127.0.0.1:<port>. The configured host from withHost(...) was only patched onto the Host header inside the request handler.

So the two halves disagreed: Laravel routed as app.localhost (subdomain routes matched) but generated every URL as 127.0.0.1. That breaks Inertia navigation, because every client-side route() (Ziggy / Wayfinder) returns a 127.0.0.1 href. Clicking a <Link> on a page served from app.localhost:<port> is then a cross-origin navigation, which drops out of the SPA into a full page load instead of an Inertia visit.

Changes

The fix resolves the canonical host in one place and syncs it into app.url and the URL generator's origin/asset origin, so route(), asset() and the Host the framework sees all agree with the host the browser is actually on.

Subdomain routing bug
Previously, the configured host (withHost(...)) was only applied ad-hoc to the Host header inside the request handler, while Laravel's app.url, route(), and asset() still pointed at the bound socket IP (127.0.0.1). This left URL generation and subdomain routing inconsistent with the host the browser was actually navigating to.

Now the canonical host is resolved in one place and synced into app.url and the URL generator's origin/asset origin/scheme. The framework consistently sees the canonical host (e.g. for subdomain routing) even when the request arrived over a different network host like 127.0.0.1. Syncing happens on boot, when the host changes via withHost() (wired through Configuration::setHost()), and per-request as a safety net.

Amp 128 KiB body limit bug

@MrPunyapal MrPunyapal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not good to merge as is. canonical fix direction is right but needs split and fixes below. pls check inline comments.

Comment thread src/Drivers/LaravelHttpServer.php Outdated
Comment thread src/Drivers/LaravelHttpServer.php Outdated
Comment thread src/Drivers/LaravelHttpServer.php Outdated
Comment thread src/Drivers/LaravelHttpServer.php Outdated
Comment thread src/Configuration.php Outdated
Comment thread tests/Browser/Visit/SubdomainTest.php
Comment thread tests/Browser/Visit/CanonicalUrlTest.php
@MrPunyapal
MrPunyapal merged commit 24b078a into pestphp:5.x Sep 14, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants