skip to Main Content

For example I have a project with the structure below

project
|_src
|_public
  |_index.php

And I run in public folder.

php -S localhost:8000

When I access

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

Here is the termial when I access the url above;

terminal stdout

It seems like every url will always go back to index.php file. I wonder why and how. Can anyone explain to me?
I tried to search but I don’t know the keyword so….

2

Answers


  1. Chosen as BEST ANSWER

    Thank you Álvaro González. The answer was documented in https://www.php.net/manual/en/features.commandline.webserver.php

    "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."


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search