Make index.php behave like a directory

Some sites (for example, some mediawiki implementations) are in uri format http://example.com/index.php/SOME_PAGE

. How it's done? Is index.php just a directory on the server called the php file name and which actually contains the file named SOME_PAGE

? If so, why do you call it that? If not (i.e. is actually some kind of legitimate PHP file) then what would the content of the content be?

0


a source to share


5 answers


This function is called path information (see Apache directiveAcceptPathInfo

).



When enabled, Apache writes the rest of the requested URI path that is already mapped to an existing file or directory in an environment variable PATH_INFO

. Therefore, if requested /index.php/SOME_PAGE

, and /index.php

is an existing file, the request is matched against that file, and the rest of the path after /index.php

( /SOME_PAGE

) is then available in a variable PATH_INFO

.

+12


a source


It doesn't behave like a directory, it just looks.

index.php is a regular php file.

Here is a tutorial on how to do it with PHP code only. The problem is you only get values ​​and you have a meaningless key in your code.

Example from the tutorial, it calls index.php / about / Evan / 2



To get about

from url it chooses

$url[0]

      

Is it not very important?

+1


a source


This is often done using a .htaccess file and mod_rewrite as well.

See this article for details .

+1


a source


Take a look at the "AcceptPathInfo" directive used by Apache (directly in httpd.conf or via .htaccess). I've been using PHP / Apache for a long time, and even longer since I've done this kind of url recycling, but this is essentially a way of passing additional data to index.php without the "normal" html syntax: var1 = Foo & var2 = bar

Note that when I did this, I configured a script called "dynamic" (or similar) as the default PHP handler and made my urls look like http: // hostname / dynamic / value1 / value2

NTN

0


a source


These sites rewrite incoming requests pointing to actual resources on the server using web server modules such as apache mod_rewrite .

0


a source







All Articles