问题
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 RewriteRule
s, 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
toSCRIPT_FILENAME
, and to not grok what PATH_INFO is. [..] You should fix your scripts to useSCRIPT_FILENAME
rather thanPATH_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