Why every request go to index.php

For example I have a project with the structure below

project
|_src
|_public
  |_index.php

And I run

php -S localhost:8000" 

in public folder.
When I access

http://localhost:8000/random/request/uri 

Here is the termial when I access the url above;
terminal stdout

it always go back to index.php file. I wonder why and how. Can anyone explain for me? Thank a lot!!

I tried to search but I don’t know the keyword so….

>Solution :

It behaves that way because that is how the PHP built-in development server was designed to work.

From the documentation:

If a URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither file exists, the lookup for index.php and index.html will be continued in the parent directory and so on until one is found or the document root has been reached. If an index.php or index.html is found, it is returned and $_SERVER[‘PATH_INFO’] is set to the trailing part of the URI. Otherwise a 404 response code is returned.

Leave a Reply