From: sam_marshall Date: Fri, 22 Sep 2006 10:48:37 +0000 (+0000) Subject: Ooops. The following-HTTP-standard absolute-path redirect thing didn't work with... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ecfdc901fc2c405318095b2a2cb2d83bde48d4b0;p=moodle.git Ooops. The following-HTTP-standard absolute-path redirect thing didn't work with URLs that begin / (i.e. it couldn't redirect to /moodle/whatever although it was fine redirecting to http://thing/moodle or to plain old whatever/something.) Fixed. --- diff --git a/lib/weblib.php b/lib/weblib.php index 96244b93d8..f10d32abee 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -4665,10 +4665,17 @@ function redirect($url, $message='', $delay=-1) { // paths - but still, might as well do it properly.) // This code turns relative into absolute. if(!preg_match('/^[a-z]+:/',$url)) { - // Add in the host etc. (from wwwroot) to the current folder - // from SCRIPT_NAME, then add the new target onto the end. - $url=preg_replace('/^(.*?[^:\/])\/.*$/','$1',$CFG->wwwroot). - rtrim(dirname($_SERVER['SCRIPT_NAME']),'/\\').'/'.$url; + // Get host name http://www.wherever.com + $hostpart=preg_replace('/^(.*?[^:\/])\/.*$/','$1',$CFG->wwwroot); + if(preg_match('/^\//',$url)) { + // URLs beginning with / are relative to web server root so + // we just add them in + $url=$hostpart.$url; + } else { + // URLs not beginning with / are relative to path of current + // script, so add that on. + $url=$hostpart.rtrim(dirname($_SERVER['SCRIPT_NAME']),'/\\').'/'.$url; + } // Replace all ..s while(true) { $newurl=preg_replace('/\/[^\/]*\/\.\.\//','/',$url);