src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php
private function resolveRedirectUrl($redirectUrl, $requestUri, $resourceLocatorPrefix)
    {
        $redirectInfo = $this->parseUrl($redirectUrl);
        $requestInfo = $this->parseUrl($requestUri);

        $url = sprintf('%s://%s', $requestInfo['scheme'], $requestInfo['host']);

        if (isset($redirectInfo['host'])) {
            $url = sprintf('%s://%s', $requestInfo['scheme'], $redirectInfo['host']);
        }

        if (isset($requestInfo['port'])) {
            $url .= ':' . $requestInfo['port'];
        }

        if (isset($redirectInfo['path'])
            && (// if requested url not starting with redirectUrl it need to be added
                !isset($requestInfo['path'])
                || 0 !== strpos($requestInfo['path'], $redirectInfo['path'] . '/'))
        ) {
            $url .= $redirectInfo['path'];
        }

        if (isset($requestInfo['path']) && $resourceLocatorPrefix !== $requestInfo['path']) {
            $path = $requestInfo['path'];
            if ($resourceLocatorPrefix && 0 === strpos($path, $resourceLocatorPrefix)) {
                $path = substr($path, strlen($resourceLocatorPrefix));
            }

            $url .= $path;
            $url = rtrim($url, '/');
        }

        if (isset($requestInfo['query'])) {
            $url .= '?' . $requestInfo['query'];
        }

        if (isset($requestInfo['fragment'])) {
            $url .= '#' . $requestInfo['fragment'];
        }

        return $url;
    }
private function resolveRedirectUrl($redirectUrl, $requestUri, $resourceLocatorPrefix)
    {
        $redirectInfo = $this->parseUrl($redirectUrl);
        $requestInfo = $this->parseUrl($requestUri);

        $url = sprintf('%s://%s', $requestInfo['scheme'], $requestInfo['host']);

        if (isset($redirectInfo['host'])) {
            $url = sprintf('%s://%s', $requestInfo['scheme'], $redirectInfo['host']);
        }

        if (isset($requestInfo['port'])) {
            $url .= ':' . $requestInfo['port'];
        }

        if (isset($redirectInfo['path'])
            && (// if requested url not starting with redirectUrl it need to be added
                !isset($requestInfo['path'])
                || 0 !== strpos($requestInfo['path'], $redirectInfo['path'] . '/'))
        ) {
            $url .= $redirectInfo['path'];
        }

        if (isset($requestInfo['path']) && $resourceLocatorPrefix !== $requestInfo['path']) {
            $path = $requestInfo['path'];
            if ($resourceLocatorPrefix && 0 === strpos($path, $resourceLocatorPrefix)) {
                $path = substr($path, strlen($resourceLocatorPrefix));
            }

            $url .= $path;
            $url = rtrim($url, '/');
        }

        if (isset($requestInfo['query'])) {
            $url .= '?' . $requestInfo['query'];
        }

        if (isset($requestInfo['fragment'])) {
            $url .= '#' . $requestInfo['fragment'];
        }

        return $url;
    }
private function resolveRedirectUrl ( $ redirectUrl , $ requestUri , $ resourceLocatorPrefix ) { $ redirectInfo = $ this -> parseUrl ( $ redirectUrl ) ; $ requestInfo = $ this -> parseUrl ( $ requestUri ) ; $ url = sprintf ( '%s://%s' , $ requestInfo [ 'scheme' ] , $ requestInfo [ 'host' ] ) ; if ( isset ( $ redirectInfo [ 'host' ] ) ) { $ url = sprintf ( '%s://%s' , $ requestInfo [ 'scheme' ] , $ redirectInfo [ 'host' ] ) ; } if ( isset ( $ requestInfo [ 'port' ] ) ) { $ url .= ':' . $ requestInfo [ 'port' ] ; } if ( isset ( $ redirectInfo [ 'path' ] ) && ( // if requested url not starting with redirectUrl it need to be added ! isset ( $ requestInfo [ 'path' ] ) || 0 !== strpos ( $ requestInfo [ 'path' ] , $ redirectInfo [ 'path' ] . '/' ) ) ) { $ url .= $ redirectInfo [ 'path' ] ; } if ( isset ( $ requestInfo [ 'path' ] ) && $ resourceLocatorPrefix !== $ requestInfo [ 'path' ] ) { $ path = $ requestInfo [ 'path' ] ; if ( $ resourceLocatorPrefix && 0 === strpos ( $ path , $ resourceLocatorPrefix ) ) { $ path = substr ( $ path , strlen ( $ resourceLocatorPrefix ) ) ; } $ url .= $ path ; $ url = rtrim ( $ url , '/' ) ; } if ( isset ( $ requestInfo [ 'query' ] ) ) { $ url .= '?' . $ requestInfo [ 'query' ] ; } if ( isset ( $ requestInfo [ 'fragment' ] ) ) { $ url .= '#' . $ requestInfo [ 'fragment' ] ; } return $ url ; }
Resolve the redirect URL, appending any additional path data.

@param string $redirectUrl Redirect webspace URI
@param string $requestUri The actual incoming request URI
@param string $resourceLocatorPrefix The prefix of the actual portal

@return string URL to redirect to
Resolve the redirect URL appending any additional path data .