src/Control/Director.php
public static function absoluteURL($url, $relativeParent = self::BASE)
    {
        if (is_bool($relativeParent)) {
            // Deprecate old boolean second parameter
            Deprecation::notice('5.0', 'Director::absoluteURL takes an explicit parent for relative url');
            $relativeParent = $relativeParent ? self::BASE : self::REQUEST;
        }

        // Check if there is already a protocol given
        if (preg_match('/^http(s?):\/\//', $url)) {
            return $url;
        }

        // Absolute urls without protocol are added
        // E.g. //google.com -> http://google.com
        if (strpos($url, '//') === 0) {
            return self::protocol() . substr($url, 2);
        }

        // Determine method for mapping the parent to this relative url
        if ($relativeParent === self::ROOT || self::is_root_relative_url($url)) {
            // Root relative urls always should be evaluated relative to the root
            $parent = self::protocolAndHost();
        } elseif ($relativeParent === self::REQUEST) {
            // Request relative urls rely on the REQUEST_URI param (old default behaviour)
            if (!isset($_SERVER['REQUEST_URI'])) {
                return false;
            }
            $parent = dirname($_SERVER['REQUEST_URI'] . 'x');
        } else {
            // Default to respecting site base_url
            $parent = self::absoluteBaseURL();
        }

        // Map empty urls to relative slash and join to base
        if (empty($url) || $url === '.' || $url === './') {
            $url = '/';
        }
        return Controller::join_links($parent, $url);
    }
public static function absoluteURL($url, $relativeParent = self::BASE)
    {
        if (is_bool($relativeParent)) {
            // Deprecate old boolean second parameter
            Deprecation::notice('5.0', 'Director::absoluteURL takes an explicit parent for relative url');
            $relativeParent = $relativeParent ? self::BASE : self::REQUEST;
        }

        // Check if there is already a protocol given
        if (preg_match('/^http(s?):\/\//', $url)) {
            return $url;
        }

        // Absolute urls without protocol are added
        // E.g. //google.com -> http://google.com
        if (strpos($url, '//') === 0) {
            return self::protocol() . substr($url, 2);
        }

        // Determine method for mapping the parent to this relative url
        if ($relativeParent === self::ROOT || self::is_root_relative_url($url)) {
            // Root relative urls always should be evaluated relative to the root
            $parent = self::protocolAndHost();
        } elseif ($relativeParent === self::REQUEST) {
            // Request relative urls rely on the REQUEST_URI param (old default behaviour)
            if (!isset($_SERVER['REQUEST_URI'])) {
                return false;
            }
            $parent = dirname($_SERVER['REQUEST_URI'] . 'x');
        } else {
            // Default to respecting site base_url
            $parent = self::absoluteBaseURL();
        }

        // Map empty urls to relative slash and join to base
        if (empty($url) || $url === '.' || $url === './') {
            $url = '/';
        }
        return Controller::join_links($parent, $url);
    }
public static function absoluteURL ( $ url , $ relativeParent = self :: BASE ) { if ( is_bool ( $ relativeParent ) ) { // Deprecate old boolean second parameter Deprecation :: notice ( '5.0' , 'Director::absoluteURL takes an explicit parent for relative url' ) ; $ relativeParent = $ relativeParent ? self :: BASE : self :: REQUEST ; } // Check if there is already a protocol given if ( preg_match ( '/^http(s?):\/\//' , $ url ) ) { return $ url ; } // Absolute urls without protocol are added // E.g. //google.com -> http://google.com if ( strpos ( $ url , '//' ) === 0 ) { return self :: protocol ( ) . substr ( $ url , 2 ) ; } // Determine method for mapping the parent to this relative url if ( $ relativeParent === self :: ROOT || self :: is_root_relative_url ( $ url ) ) { // Root relative urls always should be evaluated relative to the root $ parent = self :: protocolAndHost ( ) ; } elseif ( $ relativeParent === self :: REQUEST ) { // Request relative urls rely on the REQUEST_URI param (old default behaviour) if ( ! isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return false ; } $ parent = dirname ( $ _SERVER [ 'REQUEST_URI' ] . 'x' ) ; } else { // Default to respecting site base_url $ parent = self :: absoluteBaseURL ( ) ; } // Map empty urls to relative slash and join to base if ( empty ( $ url ) || $ url === '.' || $ url === './' ) { $ url = '/' ; } return Controller :: join_links ( $ parent , $ url ) ; }
Turns the given URL into an absolute URL. By default non-site root relative urls will be
evaluated relative to the current base_url.

@param string $url URL To transform to absolute.
@param string $relativeParent Method to use for evaluating relative urls.
Either one of BASE (baseurl), ROOT (site root), or REQUEST (requested page).
Defaults to BASE, which is the same behaviour as template url resolution.
Ignored if the url is absolute or site root.

@return string
Turns the given URL into an absolute URL . By default non - site root relative urls will be evaluated relative to the current base_url .