public function onKernelResponse(Event\FilterResponseEvent $e)
    {
        if ($e->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $response = $e->getResponse();

            // only do anything if the response has a Location header
            if (false !== ($location = $response->headers->get('location', false))) {
                $absolutePrefix = $e->getRequest()->getSchemeAndHttpHost();

                if (parse_url($location, PHP_URL_SCHEME)) {
                    if (substr($location, 0, strlen($absolutePrefix)) === $absolutePrefix) {
                        $relative = substr($location, strlen($absolutePrefix));
                    } else {
                        $relative = null;
                    }
                } else {
                    $relative = $location;
                }

                // Possible suffix for the rewrite URL
                $suffix = '';

                /**
                 * Catches the following situation:
                 *
                 * Some redirect URLs might contain extra URL parameters in the form of:
                 *
                 *      /nl/page/666/terms=FOO/tag=BAR
                 *
                 * (E.g. some SOLR implementations use this URL scheme)
                 *
                 * The relative URL above is then incorrect and the public alias can not be found.
                 *
                 * Remove /terms=FOO/tag=BAR from the relative path and attach to clean URL if found.
                 *
                 */
                if (preg_match('/^(\/[a-z]{2,2}\/page\/\d+)(.*)$/', $relative, $matches)) {
                    list(, $relative, $suffix) = $matches;
                } elseif (preg_match('/^(\/page\/\d+)(.*)$/', $relative, $matches)) {
                    /* For old sites that don't have the locale in the URI */
                    list(, $relative, $suffix) = $matches;
                }

                if (null !== $relative && null !== ($url = $this->aliasing->hasPublicAlias($relative))) {
                    $rewrite = $absolutePrefix . $url . $suffix;
                    $response->headers->set('location', $rewrite);
                }
            }

            $this->rewriteResponse($e->getRequest(), $response);
        }
    }