Detect the tracked page URL from REQUEST_URI instead of PATH_INFO - #154
Merged
Conversation
getCurrentScriptName() builds the auto-detected page URL (the path between host and query string). It preferred $_SERVER['PATH_INFO'], which only holds the trailing path-info segment — so with front- controller / path-info routing (e.g. /dir1/page handled by dir1/index.php) the tracker recorded a truncated '/page' instead of '/dir1/page'. REQUEST_URI already contains the full requested path (PATH_INFO is always just a suffix of it), so use it as the source and drop PATH_INFO entirely; SCRIPT_NAME stays as the fallback when REQUEST_URI is absent. This also aligns the primary source with Matomo core's Url helper. Reported in #141.
Keep issue references in the CHANGELOG and git history, not in code.
mneudert
approved these changes
Jul 27, 2026
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.
Supersedes #141.
Problem
getCurrentScriptName()builds the auto-detected page URL (the path between the host and the query string, consumed bygetCurrentUrl()). It preferred$_SERVER[PATH_INFO], which only holds the trailing path-info segment — always just a suffix of the requested path.With front-controller / path-info routing this truncates the URL. For a request to
https://example.com/dir1/page, wheredir1/index.phphandles/pagevia a rewrite:REQUEST_URI/dir1/pagePATH_INFO/pageSCRIPT_NAME/dir1/index.phpThe tracker recorded
/pageinstead of/dir1/page, silently dropping the directory prefix.Fix
Use
REQUEST_URIas the source (it already contains the full requested path, including any path-info) and dropPATH_INFOentirely.SCRIPT_NAMEremains the fallback whenREQUEST_URIis unavailable. This also aligns the primary source with Matomo core’sUrl::getCurrentScriptName().The original report and patch swapped the priority order but kept
PATH_INFOas a fallback; sincePATH_INFOcan only ever yield a truncated path for this method’s purpose, it is removed rather than merely deprioritized.Notes
PATH_INFO-first behavior) and added a regression test for the reporter’s scenario.Reported by @schorschii in #141.