public static function getBaseURL($url){

		$parsed_url = parse_url($url);
		if($parsed_url === false){

			throw new ErrorException('Malformed URL.');
		}

		$base_url = [];

		if(empty($parsed_url['scheme'])){

			throw new ErrorException('Malformed URL, no scheme.');
		}

		$base_url[] = $parsed_url['scheme'];
		$base_url[] = '://';
		$base_url[] = $parsed_url['host'];

		// Check the path

		$path = $parsed_url['path'];
		$path_parts = explode('/', $path);

		// Discard the first slash.

		array_shift($path_parts);
		$base = array_shift($path_parts);

		// Check if we're on localhost
		if(strpos($base, '~') !== false){

			$base_url[] = '/' . $base;
		};

		$base_url[] = '/';

		return implode('', $base_url);
	}