What happens when I put a slash (/) after the .php url?

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

Say I have a site called mysite.com. I can access the index page by 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 exactly is going on? I would think that it should return a 404 error, since index.php would be considered as a (non-existent) directory (i.e. I think it will try to find "mysite.com/index.php/index.php"). This is clearly not the case. Can someone please tell me what exactly is happening? This is also true when you put anything after a slash, that is, "mysite.com/index.php/hello"

thanks.

+7
url php slash
source share
2 answers

This is due to your Apache environment variable called PATH_INFO.

PATH_INFO

Actually, PATH_INFO is connected to the Apache web server, which serves PHP pages, not PHP.

PATH_INFO is the environment variable set by Apache when the AcceptPathInfo directive is enabled. It will contain information about the end of the path that follows the actual file name (or a nonexistent file in the existing directory), be accepted or rejected. Then the environment variables are passed to the Apache / CGI module, which is responsible for displaying the page.

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

For example, suppose location / test / points to a directory that contains only one here.html file. Then the requests to /test/here.html/more and / test / nothere.html / more are collected / more like PATH_INFO.

This answer is copied from Andrew Moore Link to original answer

+3
source share

When the server notices that the β€œdirectory” in the URL is a script, not an actual directory, it runs the script. The remaining path components in the URL are placed in the PHP variable $_SERVER['PATH_INFO'] .

+1
source share

All Articles