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));
    }