public function onKernelRequestRedirect(GetResponseEvent $event)
    {
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            if ($request->attributes->get('needsRedirect') && $request->attributes->has('semanticPathinfo')) {
                $siteaccess = $request->attributes->get('siteaccess');
                $semanticPathinfo = $request->attributes->get('semanticPathinfo');
                $queryString = $request->getQueryString();
                if (
                    $request->attributes->get('prependSiteaccessOnRedirect', true)
                    && $siteaccess instanceof SiteAccess
                    && $siteaccess->matcher instanceof URILexer
                ) {
                    $semanticPathinfo = $siteaccess->matcher->analyseLink($semanticPathinfo);
                }

                $headers = [];
                if ($request->attributes->has('locationId')) {
                    $headers['X-Location-Id'] = $request->attributes->get('locationId');
                }
                $event->setResponse(
                    new RedirectResponse(
                        $semanticPathinfo . ($queryString ? "?$queryString" : ''),
                        301,
                        $headers
                    )
                );
                $event->stopPropagation();

                if (isset($this->logger)) {
                    $this->logger->info(
                        "URLAlias made request to be redirected to $semanticPathinfo",
                        array('pathinfo' => $request->getPathInfo())
                    );
                }
            }
        }
    }
public function onKernelRequestRedirect(GetResponseEvent $event)
    {
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            if ($request->attributes->get('needsRedirect') && $request->attributes->has('semanticPathinfo')) {
                $siteaccess = $request->attributes->get('siteaccess');
                $semanticPathinfo = $request->attributes->get('semanticPathinfo');
                $queryString = $request->getQueryString();
                if (
                    $request->attributes->get('prependSiteaccessOnRedirect', true)
                    && $siteaccess instanceof SiteAccess
                    && $siteaccess->matcher instanceof URILexer
                ) {
                    $semanticPathinfo = $siteaccess->matcher->analyseLink($semanticPathinfo);
                }

                $headers = [];
                if ($request->attributes->has('locationId')) {
                    $headers['X-Location-Id'] = $request->attributes->get('locationId');
                }
                $event->setResponse(
                    new RedirectResponse(
                        $semanticPathinfo . ($queryString ? "?$queryString" : ''),
                        301,
                        $headers
                    )
                );
                $event->stopPropagation();

                if (isset($this->logger)) {
                    $this->logger->info(
                        "URLAlias made request to be redirected to $semanticPathinfo",
                        array('pathinfo' => $request->getPathInfo())
                    );
                }
            }
        }
    }
public function onKernelRequestRedirect ( GetResponseEvent $ event ) { if ( $ event -> getRequestType ( ) == HttpKernelInterface :: MASTER_REQUEST ) { $ request = $ event -> getRequest ( ) ; if ( $ request -> attributes -> get ( 'needsRedirect' ) && $ request -> attributes -> has ( 'semanticPathinfo' ) ) { $ siteaccess = $ request -> attributes -> get ( 'siteaccess' ) ; $ semanticPathinfo = $ request -> attributes -> get ( 'semanticPathinfo' ) ; $ queryString = $ request -> getQueryString ( ) ; if ( $ request -> attributes -> get ( 'prependSiteaccessOnRedirect' , true ) && $ siteaccess instanceof SiteAccess && $ siteaccess -> matcher instanceof URILexer ) { $ semanticPathinfo = $ siteaccess -> matcher -> analyseLink ( $ semanticPathinfo ) ; } $ headers = [ ] ; if ( $ request -> attributes -> has ( 'locationId' ) ) { $ headers [ 'X-Location-Id' ] = $ request -> attributes -> get ( 'locationId' ) ; } $ event -> setResponse ( new RedirectResponse ( $ semanticPathinfo . ( $ queryString ? "?$queryString" : '' ) , 301 , $ headers ) ) ; $ event -> stopPropagation ( ) ; if ( isset ( $ this -> logger ) ) { $ this -> logger -> info ( "URLAlias made request to be redirected to $semanticPathinfo" , array ( 'pathinfo' => $ request -> getPathInfo ( ) ) ) ; } } } }
Checks if the request needs to be redirected and return a RedirectResponse in such case.
The request attributes "needsRedirect" and "semanticPathinfo" are originally set in the UrlAliasRouter.

Note: The event propagation will be stopped to ensure that no response can be set later and override the redirection.

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event

@see \eZ\Publish\Core\MVC\Symfony\Routing\UrlAliasRouter
Checks if the request needs to be redirected and return a RedirectResponse in such case . The request attributes needsRedirect and semanticPathinfo are originally set in the UrlAliasRouter .