Situation
Hello, I'm confused as to PHP's expected/default behavior regarding extensionless PHP files, and/or URL requests that "go past" the actual file that (I want to) processes the request (i.e., PHP's default "fallback" actions before it resorts to completely 404-ing). Here's my situation:
My directory structure on my local server (running nginx 1.5.3 with very basic PHP 5.5.1 setup) looks like the following:
/index
/index.php
/other
/other.php
/rootdir/index
/rootdir/index.php
/rootdir/other
/rootdir/other.php
The contents of all eight files are the same:
<?php
echo $_SERVER['PHP_SELF'] . ', ' . $_SERVER['REQUEST_URI'];
?>
BUT, hitting the respective endpoint produces some strange (to me) results.
Research
GET /index.php
'/index.php, /index.php' # Makes sense...
GET /index.php/something_else
'/index.php, /index.php/something_else' # Also makes sense...
GET /index/something_else
'/index.php, /index/something_else' # Let's call this ANOMALY 1... (see below)
GET /something_else
'/index.php, /something_else' # ANOMALY 2
GET /other.php
'/other.php, /other.php' # Expected...
GET /other.php/something_else
'/index.php, /other.php/something_else' # ANOMALY 3
GET /rootdir/index.php
'/rootdir/index.php, /rootdir/index.php' # Expected...
GET /rootdir/index.php/something_else
'/index.php, /rootdir/index.php/something_else' # ANOMALY 4
GET /rootdir/other.php
'/rootdir/other.php, /rootdir/other.php' # Expected...
GET /rootdir/other.php/something_else
'/index.php, /rootdir/other.php/something_else' # ANOMALY 5
My understanding is that the server redirects to /index.php
when it is unable to find what the user is looking for at the request URI; that much makes sense... what I don't understand is:
- Why it will do this despite my not having a dedicated 404 page set up (I didn't tell it to try
/index.php
before 404-ing; I want it to display a legit, non-custom 404 page if something isn't found and/or can't be processed. I figured it should display the default server 404 page when it couldn't find something... apparently that's not always the case...?) - Why it doesn't try
/rootdir/index.php
when it can't find something within the/rootdir/
subdirectory.
Questions
Would somebody be able to shed some light on what PHP's logic is (or maybe it's nginx's doing; I haven't been able to figure that out yet) with regards to addresses that are not found? Why am I seeing what I am seeing? (Specifically with respect to Anomalies #4 and #5. I expected it to use
/rootdir/index.php
for handling it's "404," or I expected a real 404 page; the fallback to/index.php
was unexpected.)As a direct corollary (corollical?) question, how can I go about simulating extensionless PHP files that will handle hits that occur "below" them (e.g. in the Anomaly #1 case; that's actually exactly what I want, though it wasn't quite what I expected) without relying on
.htaccess
, mod_rewriting, or redirects? Or is that a silly question? :-)
References
I'm trying to roll out a custom implementation for handling requests like /some_dir/index.php/fake_subdir
and /some_other_dir/index.php/fake_subdir
(i.e., different "fallback handlers") without relying on Apache, but the logic behind PHP's (or nginx's?) default fallback behavior is eluding me. These pages are primarily where this question stems from: