protected function getRedirectUrl($target, ServerRequestInterface $request)
    {
        $param = $this->getConfig('queryParam');
        if ($param === null) {
            return $target;
        }

        $uri = $request->getUri();
        if (property_exists($uri, 'base')) {
            $uri = $uri->withPath($uri->base . $uri->getPath());
        }
        $query = urlencode($param) . '=' . urlencode($uri);

        $url = parse_url($target);
        if (isset($url['query']) && strlen($url['query'])) {
            $url['query'] .= '&' . $query;
        } else {
            $url['query'] = $query;
        }
        $fragment = isset($url['fragment']) ? '#' . $url['fragment'] : '';

        return $url['path'] . '?' . $url['query'] . $fragment;
    }