Skip to content

HTTP routing

Andrea Mecchia edited this page Jul 4, 2018 · 8 revisions

Index > HTTP routing


The traditional approach

In a traditional HTTP-PHP server when a client makes a request with the form GET http[s]://domain.tld/path/to/folder or GET http[s]://domain.tld/path/to/file.ext the corresponding file or (by-default) the index.php file contained in the corresponding folder is sent back in response to the client request.

If the file is not found the server generates a 404 not found error.

With HTTP routing

With HTTP routing, we can alter the natural request/response flow by intercepting the request and executing specific code based on it. This helps to mantain a clean project and allows us to use other features like route parameters and filter-on-method.

HTTP routing comes to the rescue only if the requested file or folder is not found. All requests that cannot be served because the requested file or folder doesn't exist are redirected to the public/index.php file where the request is processed by the application routers.

This means that we can combine the two approches: for example we can serve static files from the document root while using HTTP routing for dynamic content.