public static function detectBaseURL(){

		if(PHP_SAPI == 'cli') return 'http://php-cli.invalid/';

		$protocol = 'http://';

		if(isset($_SERVER['HTTPS']) &&
			filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)){

			$protocol = 'https://';
		}

		/*
		 * We use Apache's user-dir feature for our local development
		 * environments (e.g. "http://localhost/~Academic/"). In order for
		 * base URL detection to properly pick up on these URL's we  use the
		 * CONTEXT_PREFIX environment variable provided by recent (2.3.13+)
		 * versions of Apache.
		 */

		if(isset($_SERVER['CONTEXT_PREFIX'])){

			$path = trim($_SERVER['CONTEXT_PREFIX'], '/\\') . '/';
		}
		else{

			$path = './';
		}

		return self::normaliseURL("{$protocol}{$_SERVER['HTTP_HOST']}/{$path}");
	}