From d909a489f6c98058326d1c0b4db93e217cd42b6d Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Wed, 28 Oct 2026 11:15:16 +0800 Subject: [PATCH] Fix case-insensitive handling of .php extensions --- public/error.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/public/error.php b/public/error.php index 34b0e0a51f..b908dc0557 100644 --- a/public/error.php +++ b/public/error.php @@ -181,19 +181,21 @@ mirror_redirect("https://github.com/php/php-src/issues/" . $matches[1]); } -// php.net/supported-versions.PHP -> supported-versions.php -if ($URI == 'supported-versions.PHP') { - mirror_redirect("https://www.php.net/supported-versions.php"); -} - +// Fix for case-insensitive .php extension, e.g. /supported-versions.PHP, /downloads.PHP +$originalURI = $URI; +$URI = preg_replace('/\.php\z/i', '.php', $URI); // ============================================================================ // Redirect if the entered URI was a PHP page name (except some pages, // which we display in the mirror's language or the explicitly specified // language [see below]) -if (!in_array($URI, ['mirror-info', 'error', 'mod'], true) && - file_exists(ProjectGlobals::getPublicRoot() . "/$URI.php")) { - mirror_redirect("/$URI.php"); +$hasPhpExtension = str_ends_with($URI, '.php'); +$phpPage = $hasPhpExtension ? $URI : "$URI.php"; +$phpPageName = $hasPhpExtension ? substr($URI, 0, -4) : $URI; +if (!in_array($phpPageName, ['mirror-info', 'error', 'mod'], true) && + file_exists(ProjectGlobals::getPublicRoot() . "/$phpPage") && + (!$hasPhpExtension || $URI !== $originalURI)) { + mirror_redirect("/$phpPage"); } // Work with lowercased URI from now