diff --git a/lib/setuplib.php b/lib/setuplib.php index af340a89e0c..d25b1f6a7d4 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -958,7 +958,13 @@ function initialise_fullme() { throw new moodle_exception('requirecorrectaccess', 'error', '', null, 'You called ' . $calledurl .', you should have called ' . $correcturl); } - redirect($CFG->wwwroot . $rurl['fullpath'], get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); + $rfullpath = $rurl['fullpath']; + // Check that URL is under $CFG->wwwroot. + if (strpos($rfullpath, $wwwroot['path']) === 0) { + $rfullpath = substr($rurl['fullpath'], strlen($wwwroot['path']) - 1); + $rfullpath = (new moodle_url($rfullpath))->out(false); + } + redirect($rfullpath, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); } }