Why is $ _SERVER ['PATH_TRANSLATED'] repeated?

I am trying to create an MVC structure when I notice that the variable $ _SERVER ['PATH_TRANSLATED'] does this:

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

This is when I access the PHP file http: //domain.tld/test/test2/test3
Note how this repeats after / test /

This is my .htaccess to rewrite:

<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 to change the RewriteRule rule, but nothing changed. The variable is not so important for what I'm trying to do, but I wonder why this happens, and if I have something incorrectly configured.

Server Information:
Apache / 2.2.3
PHP 5.3.1

Edit: This variable is not repeated in Lighttpd, as it reports:

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

So, I assume this has something to do with Apache. I also tried FastCGI under Apache and produced the same duplicate result.

+4
source share
1 answer

If you use mod_rewrite , then reading the value of PATH_TRANSLATED will not be used in your script, since it will point to a file or path of nonexistence. You must use PATH_INFO in your index.php to find out the URI that was requested by the user.

As an example, you can look at the CodeIgniter router class . CodeIgniter can use several methods to get the URI parameters: PATH_INFO , QUERY_STRING , REQUEST_URI and ORIG_PATH_INFO .

If you are still curious about the strange behavior of your Apache, perhaps breaking into the access log, you will see the key to the culprit. However, if you are not using this variable, just forget it. It serves a different purpose, and your MVC will not use it.

+3
source

Source: https://habr.com/ru/post/1301269/


All Articles