diff --git a/lib/classes/router.php b/lib/classes/router.php index 2a0a94d3412e0..0529a18e611f9 100644 --- a/lib/classes/router.php +++ b/lib/classes/router.php @@ -92,14 +92,17 @@ protected function guess_basepath(): string { // Moodle is not guaranteed to exist at the domain root. // Strip out the current script. $scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH); + $scriptfile = str_replace( + realpath($CFG->dirroot), + '', + realpath($_SERVER['SCRIPT_FILENAME']), + ); + // Replace occurrences of backslashes with forward slashes, especially on Windows. + $scriptfile = str_replace('\\', '/', $scriptfile); $relativeroot = sprintf( '%s%s', $scriptroot, - str_replace( - realpath($CFG->dirroot), - '', - realpath($_SERVER['SCRIPT_FILENAME']), - ), + $scriptfile, ); // The server is not configured to rewrite unknown requests to automatically use the router.