I use a .htaccess
file to redirect all requests to the same index.php
. From there, I decide what to do depending on URL of the incoming request.
For now, I map the request URL to directory structure relative to a source
folder, so that example.com/user/create
maps to source/user/create/index.php
. The file located there can handle the request as needed, and generate HTML output.
But that doesn't work for static assets, the browser may request. So my idea is to find out whether a request URL ends with a file extension and map that to a directory structure relative to a assets
folder, so that example.com/css/default.css
would map to assets/css/default.css
. But I don't know how to respond with a static file instead of HTML code from PHP.
Normally, this might be done using an additional .htaccess
rule, but I'd like to change the assets folder dynamically in code.
How can I send a static file, given on the server's hard drive, to the browser client in PHP?