PHP: $_SERVER['REDIRECT_URL'] vs $_SERVER['REQUEST_URI']

前端 未结 3 1720
旧时难觅i
旧时难觅i 2020-12-08 07:02

I printed $_SERVER, and I found out that $_SERVER[\'REDIRECT_URL\'] vs $_SERVER[\'REQUEST_URI\'] both have same values. What\'s the difference betw

相关标签:
3条回答
  • 2020-12-08 07:09

    REQUEST_URI is the requested URI path and query as used in the HTTP request line. REDIRECT_URL is created by Apache when an internal redirect happens:

    REDIRECT_ environment variables are created from the environment variables which existed prior to the redirect. They are renamed with a REDIRECT_ prefix, i.e., HTTP_USER_AGENT becomes REDIRECT_HTTP_USER_AGENT.

    REDIRECT_URL, REDIRECT_STATUS, and REDIRECT_QUERY_STRING are guaranteed to be set, and the other headers will be set only if they existed prior to the error condition.

    Note that REDIRECT_URL does only contain the URI path.

    0 讨论(0)
  • 2020-12-08 07:15

    $_SERVER['REDIRECT_URL'] is only available on some servers in some cases. Use $_SERVER['REQUEST_URI'] instead.

    0 讨论(0)
  • 2020-12-08 07:17

    REQUEST_URI also changes special chars like spaces to "%20" etc.

    0 讨论(0)
提交回复
热议问题