if (array_key_exists('REDIRECT_URL', $_SERVER)) {
$url = $_SERVER['REDIRECT_URL'];
} else {
$url = $_SERVER['REQUEST_URI'];
}
When redirecting to a local URL, additional environment variables are set so that the response can be further customized. They are not sent to external URLs.
fastcgi_param REDIRECT_URL $uri;