What is redirect:// in PATH_TRANSLATED?

左心房为你撑大大i 提交于 2019-12-31 02:15:42

问题


I have a .htaccess rule that passes requests for /category/category-slug/ to category.php. However, when I inspect the $_SERVER super-global, I get this entry:

Array
(
    [PATH_TRANSLATED] => redirect://
)

What is that? I’ve never seen redirect:// before.

This is the relavant .htaccess rule:

RewriteRule ^category/([^/]+)/?(.*) /category.php?cat=$1&page=$2 [L,QSA]

As a result, I’m not getting $_GET['cat'] or $_GET['page'] populated in my script as it seems to be coming from a redirect and not having the request being simply re-written. What’s going on?


回答1:


I found an Apache bug report (40781) about what seems to be the same issue. To quote the comment by Bob Ionescu:

"The problem is that the subrequest with uri=path_info of the main request (in order to obtain path_translated, i.e. the physical path view of path_info) hits the RewriteRule in per-directory context again and matches; hence no physical path.

Why does this not occur in Apache 2.0? The answer is simple: mod_rewrite doesn't act in subrequests in per-directory context prior version 2.1. The NS flag prevents the processing of RewriteRules in subrequests."

The comment suggests that you should be able to fix this issue by including the [NS] flag in your RewriteRules, unless you explicitly want them to apply to subrequests too.




回答2:


PATH_TRANSLATED in $_SERVER is an environment variable of your server that gets imported by PHP into the $_SERVER superglobal following some standard rules. So the environment variable is similarly if not identically named.

Only by the name of the environment variable it can not be said what exactly has set this value, however the context of your question suggests that it has been set by the Aapache HTTPD webserver.




回答3:


The PHP documentation says the following:

PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. [..] You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.

Also see $_SERVER with a slightly different note:

Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly under the Apache 2 SAPI in contrast to the situation in Apache 1, where it's set to the same value as the SCRIPT_FILENAME server variable when it's not populated by Apache. This change was made to comply with the CGI specification that PATH_TRANSLATED should only exist if PATH_INFO is defined. Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.

All of the $_SERVER variables are read from the environment. In case of Apache + mod_php this environment is defined by the Apache server.

To be honest I either didn't see redirect:// so far. Are you sure, your request matches this rewrite rule and not another before?

I think mod_rewrite is the place you have to look for an error.

You can debug what mod_rewrite does by enabling logs



来源:https://stackoverflow.com/questions/14113593/what-is-redirect-in-path-translated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!