Returns root relative url.
@param string $baseUrl base url to create absolute url.
@return string
@throws \Exception if baseUrl is invalid
480499
public function rootRelative($baseUrl)
    {
        $url = $this->url;

        $parsedBaseUrl = parse_url($baseUrl) + array(
                'path' => '',
            );
        if (!isset($parsedBaseUrl['scheme'], $parsedBaseUrl['host'])) {
            throw new \Exception('Invalid base url "' . $baseUrl . '": scheme not found.');
        }

        if (empty($url)) {
            return $parsedBaseUrl['path'] . (isset($parsedBaseUrl['query']) ? '?' . $parsedBaseUrl['query'] : '');
        }

        $parsedUrl = parse_url($url) + array(
                'path' => '/',
            );
        if (substr($url, 0, 1) == '?') {
            return $parsedBaseUrl['path'] . $url;
        }

        if (substr($url, 0, 3) == '../') {
            $pathParts = explode('/', $parsedBaseUrl['path']);
            array_pop($pathParts);

            while (substr($url, 0, 3) == '../') {
                array_pop($pathParts);
                $url = substr($url, 3);
            }

            return implode('/', $pathParts) . '/' . $url;
        }

        return $parsedUrl['path'] . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');
    }
112666
protected function createBaseRequest($relativeUrl)
	{
		$baseUrl = $this->getBaseUrl(false);
		$request = new \Zend\Http\Request();
		$request->setUri($baseUrl.$relativeUrl);
		$request->setMethod(\Zend\Http\Request::METHOD_POST);
		$request->getHeaders()->addHeaders(array(
			'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
			'Accept-Encoding'=>'identity')); // plain text

		$this->addDefaultParameters($request);

		return $request;
	}
504481
public static function getBaseUrl() : string
    {
        $https = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? 'https://' : 'http://';

        return $https . rtrim(rtrim($_SERVER['HTTP_HOST'], '\\/') . dirname($_SERVER['PHP_SELF']), '\\/');
    }
899668
public function baseUrl()
    {
        static $base = null;
        if ($base === null) {
            $base = $this->_View->request->base;
        }

        return $base;
    }
837890
public function relativePath($url) {
        $path = $this->toPath($url);
        if (!preg_match('#'.$this->config['path'].'#', $path, $matches)) {
            throw new Exception("$url doesn't match `{$this->config['path']}`");
        }
        return $matches[1];
    }
1163455
protected function getBaseUrl()
    {
        $baseUrl = $this->container->get('router')->getContext()->getBaseUrl();

        if ($baseUrl === '/') {
            return '';
        }

        return rtrim(str_replace('app_dev.php', '', $this->container->get('router')->getContext()->getBaseUrl()), '/').'/';
    }
629761
public static function getRootDomain($url)
    {
        $host = $domain = self::getHostname($url);
        $root = false;

        if (($dotsCount = substr_count($host, '.')) > 0) {
            $last = $domain;
            while ($dotsCount > -1) {
                if (self::isHostInSuffixList($domain)) {
                    $root = $last;
                    break;
                }
                $last = trim($domain, '.');
                $domain = substr($last, strpos($last, '.'));
                $dotsCount = $dotsCount - 1;
            }
        }

        return $root;
    }
81774
private function getUrl(string $url): string
    {
        $urlParts = parse_url($url);

        if ($urlParts === false) {
            throw new \ParseError("Could not parse URL: $url");
        }

        if ($this->baseUrl !== null && ! isset($urlParts['host'])) {
            $url = $this->baseUrl . '/' . ltrim($url, '/');
        }

        return $url;
    }
20084
public static function base($url) {
        if (preg_match('#^(/|(ht|f)tps?://).+#', $url)) {
            return $url;
        }
        $url = preg_replace('#/?index\.html?$#', '', $url);

        return WWWROOT_DIR . $url;
    }
466353
public function rootUrl($include_host = false)
    {
        if ($include_host) {
            return $this->root;
        }

        return str_replace($this->base, '', $this->root);
    }
908086
public static function getRootUrl($url)
  {
    $url_parts = self::splitURL($url);
    $root_url = $url_parts["protocol"].$url_parts["host"].":".$url_parts["port"];
    
    return self::normalizeURL($root_url);
  }
742266
public function setBaseUrl($baseUrl)
    {
        if ($baseUrl) {
            if (UrlHelper::isUrl($baseUrl)) {
                $this->baseUrl = rtrim($baseUrl, '/') . '/';
            } else {
                $this->baseUrl = rtrim($baseUrl, '/') . '/';
            }
        }

        return $this;
    }
1077403
public function getBaseUrl($absolute = false)
    {
        $url = array();
        if ($absolute) {
            $url[] = $this->baseUrl !== null ? rtrim($this->baseUrl, '/') : Yii::app()->request->baseUrl;
        }
        $url[] = $this->fileDir;
        return rtrim(implode('/', $url), '/');
    }
634480
public function setBaseUrl($url)
    {
        if (substr($url, -1) != '/') {
            $url .= '/';
        }

        if (substr($url,-4,4) != 'api/') {
            $url .= 'api/';
        }

        $this->baseUrl = $url;

        return $this;
    }
1138060
private function getRequest($url)
    {
        if ($this->baseUri && substr($url, 0, 1) != '/') {
            throw new \InvalidArgumentException(
                sprintf("Invalid uri '%s' with baseUri '%s'", $url, $this->baseUri->get(false))
            );
        }

        if ($this->baseUri && $url) {
            $uri = clone $this->baseUri;
            $uri->setPath($uri->getPath() . $url);
        } else {
            $uri = $url instanceof Uri ? $url : new Uri($url);
        }

        return new Request($uri);
    }
922007
public function rootUrl()
    {
        $base = $this->root();
        $root = strpos($base, '.') ? ltrim(dirname($base), DIRECTORY_SEPARATOR) : $base;
        if ('' != $root) {
            $root = '/' . ltrim($root, '/');
        }
        return $root;
    }
1201002
private function getBaseUrl() {
        $uri = $this->getRequest()->getUri();
        return sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
    }