fix: prevent subdomain-only route from overwriting hostname route#10211
Open
jalexiscv wants to merge 1 commit into
Open
fix: prevent subdomain-only route from overwriting hostname route#10211jalexiscv wants to merge 1 commit into
jalexiscv wants to merge 1 commit into
Conversation
Fixes codeigniter4#7214 When routes with both 'hostname' and 'subdomain' options are defined separately, a less specific subdomain-only route could overwrite a more specific hostname-matched route due to registration order. Changes: - Change 'elseif' to 'if' so both hostname and subdomain checks are independent. A route with both options now validates both. - Track matchedByHostname/matchedBySubdomain flags during registration - Add guard to prevent a route matched only by subdomain from overwriting an existing route that was registered with hostname, since hostname specificity should take precedence. Ref: codeigniter4#7214
|
Hi there, jalexiscv! 👋 Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md Sincerely, the mergeable bot 🤖 |
paulbalandan
requested changes
May 18, 2026
Member
paulbalandan
left a comment
There was a problem hiding this comment.
Please add tests to prove the fix works. Also, add the fix to the changelog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #7214 - Inconsistent hostname/subdomain limitation in Routing
Problem
When using
hostnameandsubdomainroute options, the precedence was inconsistent depending on whether they were on the same route or separate routes:Case 1: Same route (hostname took precedence - correct)
media.example.com → Media::index ✓
Case 2: Separate routes (subdomain incorrectly won)
media.example.com → All::index ✗ (should be Media::index)
Root Cause
Two issues:
elseifmeant routes with bothhostnameandsubdomainonly validated hostnameSolution
elseiftoif— bothhostnameandsubdomainare validated independentlymatchedByHostname/matchedBySubdomainflags during registrationChanges
One file:
system/Router/RouteCollection.phpRef: #7214
Closes #7214