Skip to content

Detect the tracked page URL from REQUEST_URI instead of PATH_INFO - #154

Merged
sgiehl merged 2 commits into
masterfrom
fix-page-url-detection-request-uri
Jul 27, 2026
Merged

Detect the tracked page URL from REQUEST_URI instead of PATH_INFO#154
sgiehl merged 2 commits into
masterfrom
fix-page-url-detection-request-uri

Conversation

@sgiehl

@sgiehl sgiehl commented Jul 27, 2026

Copy link
Copy Markdown
Member

Supersedes #141.

Problem

getCurrentScriptName() builds the auto-detected page URL (the path between the host and the query string, consumed by getCurrentUrl()). 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, where dir1/index.php handles /page via a rewrite:

Variable Value
REQUEST_URI /dir1/page
PATH_INFO /page
SCRIPT_NAME /dir1/index.php

The tracker recorded /page instead of /dir1/page, silently dropping the directory prefix.

Fix

Use REQUEST_URI as the source (it already contains the full requested path, including any path-info) and drop PATH_INFO entirely. SCRIPT_NAME remains the fallback when REQUEST_URI is unavailable. This also aligns the primary source with Matomo core’s Url::getCurrentScriptName().

The original report and patch swapped the priority order but kept PATH_INFO as a fallback; since PATH_INFO can only ever yield a truncated path for this method’s purpose, it is removed rather than merely deprioritized.

Notes

  • Behavior change only affects sites using path-info routing, and moves them from a broken to a correct URL.
  • Updated the existing unit tests (which asserted the old PATH_INFO-first behavior) and added a regression test for the reporter’s scenario.
  • CHANGELOG updated under 4.0.0.

Reported by @schorschii in #141.

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.
@sgiehl sgiehl mentioned this pull request Jul 27, 2026
9 tasks
Keep issue references in the CHANGELOG and git history, not in code.
@sgiehl
sgiehl merged commit cf976bf into master Jul 27, 2026
18 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