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

        $request = $event->getRequest();

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

        $prefix = $attributes->getAttribute('resourceLocatorPrefix');
        $resourceLocator = $attributes->getAttribute('resourceLocator');

        $route = '/' . trim($prefix . $resourceLocator, '/');
        if (!in_array($request->getRequestFormat(), ['htm', 'html'])
            || $route === $request->getPathInfo()
            || !$this->matchRoute($request->getSchemeAndHttpHost() . $route)
        ) {
            return;
        }

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

        $request = $event->getRequest();

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

        $prefix = $attributes->getAttribute('resourceLocatorPrefix');
        $resourceLocator = $attributes->getAttribute('resourceLocator');

        $route = '/' . trim($prefix . $resourceLocator, '/');
        if (!in_array($request->getRequestFormat(), ['htm', 'html'])
            || $route === $request->getPathInfo()
            || !$this->matchRoute($request->getSchemeAndHttpHost() . $route)
        ) {
            return;
        }

        $event->setResponse(new RedirectResponse($route, 301));
    }
public function redirectTrailingSlashOrHtml ( GetResponseForExceptionEvent $ event ) { if ( ! $ event -> getException ( ) instanceof NotFoundHttpException ) { return ; } $ request = $ event -> getRequest ( ) ; /** @var RequestAttributes $attributes */ $ attributes = $ request -> attributes -> get ( '_sulu' ) ; if ( ! $ attributes ) { return ; } $ prefix = $ attributes -> getAttribute ( 'resourceLocatorPrefix' ) ; $ resourceLocator = $ attributes -> getAttribute ( 'resourceLocator' ) ; $ route = '/' . trim ( $ prefix . $ resourceLocator , '/' ) ; if ( ! in_array ( $ request -> getRequestFormat ( ) , [ 'htm' , 'html' ] ) || $ route === $ request -> getPathInfo ( ) || ! $ this -> matchRoute ( $ request -> getSchemeAndHttpHost ( ) . $ route ) ) { return ; } $ event -> setResponse ( new RedirectResponse ( $ route , 301 ) ) ; }
Redirect trailing slashes or ".html".

@param GetResponseForExceptionEvent $event
Redirect trailing slashes or . html .