Why is $_SERVER['PATH_TRANSLATED'] repeati

2019-02-24 08:24发布

I'm trying to create a MVC framework when I noticed the $_SERVER['PATH_TRANSLATED'] variable is doing this:

[PATH_INFO] => /test/test2/test3
[PATH_TRANSLATED] => redirect:/index.php/test/test2/test3/test2/test3

This is when I'm accessing the PHP file by http://domain.tld/test/test2/test3
Notice how it is repeating after /test/

This is my .htaccess for rewriting:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Any ideas? I tried changing the RewriteRule rule around but nothing changed. The variable isn't that important for what I am trying to do however, I am wondering why this is happening and if I have something misconfigured.

Server Info:
Apache/2.2.3
PHP 5.3.1

Edit: This variable doesn't repeat itself under Lighttpd, as it reports:

[PATH_INFO] => /test/test2/test3
[PATH_TRANSLATED] => /home/kramer/public_html/test/test2/test3

So I am assuming it has something to do with Apache. I also tried FastCGI under Apache and it produced the same repeating result.

1条回答
不美不萌又怎样
2楼-- · 2019-02-24 09:24

If you are using mod_rewrite, then reading the PATH_TRANSLATED value will have no use in your script, since it will point to a non-existence file or path. You should use PATH_INFO in your index.php to know the URI that was requested by user.

For an example, you can take a look at CodeIgniter's Router class. CodeIgniter can use several ways to get the URI parameters: PATH_INFO, QUERY_STRING, REQUEST_URI, and ORIG_PATH_INFO.

If you are still curious with the strange behavior of your Apache, maybe digging into the access log will reveal some clue to the culprit. However, if you are not using this variable, just forget it. It serves a different purpose, and your MVC will not be going to use it.

查看更多
登录 后发表回答