Why is $_SERVER['PATH_TRANSLATED'] repeating itself?

0

Issue

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.

Solution

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.

Answered By – Donny Kurnia

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More