Reputation: 172
I wanted to know if it is possible to treat a php file as a directory so that index.php/abc/def
really calls index.php. The index.php should then know the subdirectory path (ie /abc/def
).
I'm searching a plain php solution. I know that I could use mod_rewrite to map the directory to GET-parameters.
Upvotes: 0
Views: 385
Reputation: 449465
This will work if Apache's AcceptPathInfo
directive is turned on, which is the default. From the manual:
The treatment of requests with trailing pathname information is determined by the handler responsible for the request. The core handler for normal files defaults to rejecting PATH_INFO requests. Handlers that serve scripts, such as cgi-script and isapi-handler, generally accept PATH_INFO by default.
you can query the path entered using the $_SERVER["PATH_INFO"]
directive. You'll have to parse the paths yourself inside the script.
Upvotes: 3
Reputation: 2669
If I recall correctly, you should be able to parse out this info from $_SERVER['PHP_SELF'].
Edit: Even better, take a look at $_SERVER["PATH_INFO"].
Upvotes: 3
Reputation: 132
A plain PHP solution is impossible since what is called will be the file.
The PHP in the file does not care where it is or how the file it is in is called other than for include purpose.
What you are looking for is to either convince the OS to pass the /abc/def/ as a parameter to the script or to get the Webserver to do the same thing (ie. mod_rewrite for apache).
Upvotes: 1