8

I have a simple question, but could not find the answer anywhere

say I have a site "mysite.com". I can access the index page by either typing "mysite.com" or "mysite.com/index.php". This works fine... however, when i try to go to "mysite.com/index.php/" the page loads, but not correctly. what is exactly happening? I would think it should return a 404 error, since index.php would be treated as a (non existing) directory (i.e. i would think it would try to find "mysite.com/index.php/index.php"). This clearly isn't the case. Can someone please tell me what exactly is happening? This is also true when you put anything after the slash, i.e. "mysite.com/index.php/hello"

thanks.

Guy
  • 81
  • 1
  • 3
  • It's just treated as PATH_INFO. The virtual path fragment however breaks relative resource links (css, images). – mario Jan 23 '14 at 04:18
  • thanks for the reply. i still don't quite understand. whats is the point of allowing such a url to be valid in the first place? why not just return 404 error? – Guy Jan 23 '14 at 04:21

2 Answers2

4

This is due to your Apache environmental variable called PATH_INFO.

PATH_INFO

Actually, PATH_INFO is related to the Apache Web Server serving PHP pages and not PHP per-say.

PATH_INFO is an environment variable set by Apache when the AcceptPathInfo directive is turned on. It will contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. Environment variables are then passed on to the Apache/CGI module in charge of rendering the page.

The variable is accessible in PHP using $_SERVER['PATH_INFO'].

For example, assume the location /test/ points to a directory that contains only the single file here.html. Then requests for /test/here.html/more and /test/nothere.html/more both collect /more as PATH_INFO.

This answer is copied from Andrew Moore Link to original answer

Community
  • 1
  • 1
Lal krishnan S L
  • 1,684
  • 1
  • 16
  • 32
  • Is this really unique to Apache? NGINX won't do the same thing? – Barmar Jan 23 '14 at 04:22
  • 3
    Attribution is required if you copy from other answers. – mario Jan 23 '14 at 04:22
  • 3
    Please see [citation advise](http://meta.stackexchange.com/questions/115816/how-should-i-attribute-excerpts-of-code-from-other-stack-overflow-posts/115820#115820). At the very least mention the author, and don't hide it in an undescriptive Link below the verbatim copy. – mario Jan 23 '14 at 04:35
1

When the server notices that a "directory" in the URL is a script rather than an actual directory, it runs the script. The remaining components of the path in the URL are put in the PHP variable $_SERVER['PATH_INFO'].

Barmar
  • 741,623
  • 53
  • 500
  • 612