Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading