PHP:$_SERVER['REDIRECT_URL'] 与 $_SERVER['REQUEST_URI']
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6483912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: $_SERVER['REDIRECT_URL'] vs $_SERVER['REQUEST_URI']
提问by evilReiko
I printed $_SERVER, and I found out that $_SERVER['REDIRECT_URL']vs $_SERVER['REQUEST_URI']both have same values. What's the difference between the two?
我打印了 $_SERVER,我发现 $ _SERVER['REDIRECT_URL']vs$_SERVER['REQUEST_URI']两者具有相同的值。两者有什么区别?
回答by Gumbo
REQUEST_URIis the requested URI path and query as used in the HTTP request line. REDIRECT_URLis created by Apachewhen an internal redirect happens:
REQUEST_URI是请求的 URI 路径和在HTTP 请求行中使用的查询。REDIRECT_URL是在发生内部重定向时由 Apache 创建的:
REDIRECT_environment variables are created from the environment variables which existed prior to the redirect. They are renamed with aREDIRECT_prefix, i.e.,HTTP_USER_AGENTbecomesREDIRECT_HTTP_USER_AGENT.
REDIRECT_URL,REDIRECT_STATUS, andREDIRECT_QUERY_STRINGare guaranteed to be set, and the other headers will be set only if they existed prior to the error condition.
REDIRECT_环境变量是从重定向之前存在的环境变量创建的。它们用REDIRECT_前缀重命名,即HTTP_USER_AGENT变成REDIRECT_HTTP_USER_AGENT。
REDIRECT_URL,REDIRECT_STATUS, 和REDIRECT_QUERY_STRING保证被设置,并且其他标头只有在错误条件之前存在时才会被设置。
Note that REDIRECT_URLdoes only contain the URI path.
请注意,REDIRECT_URL仅包含 URI 路径。
回答by Sjoerd
$_SERVER['REDIRECT_URL']is only available on some servers in some cases. Use $_SERVER['REQUEST_URI']instead.
$_SERVER['REDIRECT_URL']在某些情况下仅在某些服务器上可用。使用$_SERVER['REQUEST_URI']来代替。
回答by Jan Salák
REQUEST_URI also changes special chars like spaces to "%20" etc.
REQUEST_URI 还将特殊字符(如空格)更改为“%20”等。

