src/Sulu/Bundle/WebsiteBundle/EventListener/RedirectExceptionSubscriber.php
public function redirectPartialMatch(GetResponseForExceptionEvent $event)
    {
        if (!$event->getException() instanceof NotFoundHttpException) {
            return;
        }

        $request = $event->getRequest();

        /** @var RequestAttributes $attributes */
        $attributes = $event->getRequest()->attributes->get('_sulu');
        if (!$attributes) {
            return;
        }

        $types = [RequestAnalyzerInterface::MATCH_TYPE_REDIRECT, RequestAnalyzerInterface::MATCH_TYPE_PARTIAL];
        $matchType = $attributes->getAttribute('matchType');
        if (!in_array($matchType, $types)) {
            return;
        }

        $localization = $this->defaultLocaleProvider->getDefaultLocale();

        $redirect = $attributes->getAttribute('redirect');
        $redirect = $this->urlReplacer->replaceCountry($redirect, $localization->getCountry());
        $redirect = $this->urlReplacer->replaceLanguage($redirect, $localization->getLanguage());
        $redirect = $this->urlReplacer->replaceLocalization($redirect, $localization->getLocale(Localization::DASH));

        $route = $this->resolveRedirectUrl(
            $redirect,
            $request->getUri(),
            $attributes->getAttribute('resourceLocatorPrefix')
        );

        if (!$this->matchRoute($route)) {
            return;
        }

        $event->setResponse(new RedirectResponse($route, 301));
    }
public function redirectPartialMatch(GetResponseForExceptionEvent $event)
    {
        if (!$event->getException() instanceof NotFoundHttpException) {
            return;
        }

        $request = $event->getRequest();

        /** @var RequestAttributes $attributes */
        $attributes = $event->getRequest()->attributes->get('_sulu');
        if (!$attributes) {
            return;
        }

        $types = [RequestAnalyzerInterface::MATCH_TYPE_REDIRECT, RequestAnalyzerInterface::MATCH_TYPE_PARTIAL];
        $matchType = $attributes->getAttribute('matchType');
        if (!in_array($matchType, $types)) {
            return;
        }

        $localization = $this->defaultLocaleProvider->getDefaultLocale();

        $redirect = $attributes->getAttribute('redirect');
        $redirect = $this->urlReplacer->replaceCountry($redirect, $localization->getCountry());
        $redirect = $this->urlReplacer->replaceLanguage($redirect, $localization->getLanguage());
        $redirect = $this->urlReplacer->replaceLocalization($redirect, $localization->getLocale(Localization::DASH));

        $route = $this->resolveRedirectUrl(
            $redirect,
            $request->getUri(),
            $attributes->getAttribute('resourceLocatorPrefix')
        );

        if (!$this->matchRoute($route)) {
            return;
        }

        $event->setResponse(new RedirectResponse($route, 301));
    }
public function redirectPartialMatch ( GetResponseForExceptionEvent $ event ) { if ( ! $ event -> getException ( ) instanceof NotFoundHttpException ) { return ; } $ request = $ event -> getRequest ( ) ; /** @var RequestAttributes $attributes */ $ attributes = $ event -> getRequest ( ) -> attributes -> get ( '_sulu' ) ; if ( ! $ attributes ) { return ; } $ types = [ RequestAnalyzerInterface :: MATCH_TYPE_REDIRECT , RequestAnalyzerInterface :: MATCH_TYPE_PARTIAL ] ; $ matchType = $ attributes -> getAttribute ( 'matchType' ) ; if ( ! in_array ( $ matchType , $ types ) ) { return ; } $ localization = $ this -> defaultLocaleProvider -> getDefaultLocale ( ) ; $ redirect = $ attributes -> getAttribute ( 'redirect' ) ; $ redirect = $ this -> urlReplacer -> replaceCountry ( $ redirect , $ localization -> getCountry ( ) ) ; $ redirect = $ this -> urlReplacer -> replaceLanguage ( $ redirect , $ localization -> getLanguage ( ) ) ; $ redirect = $ this -> urlReplacer -> replaceLocalization ( $ redirect , $ localization -> getLocale ( Localization :: DASH ) ) ; $ route = $ this -> resolveRedirectUrl ( $ redirect , $ request -> getUri ( ) , $ attributes -> getAttribute ( 'resourceLocatorPrefix' ) ) ; if ( ! $ this -> matchRoute ( $ route ) ) { return ; } $ event -> setResponse ( new RedirectResponse ( $ route , 301 ) ) ; }
Redirect partial and redirect matches.

@param GetResponseForExceptionEvent $event
Redirect partial and redirect matches .