Apache FallbackResource for front-loaded applications
Many frameworks we use are front-loaded. This means that we have a web-root with an index file that handles all application requests.
In PHP frameworks, this is usually the public/index.php
file.
We often use Mod_Rewrite to "hide" the index.php file our URL. These rules often check to see if the requested resource does not exist. If it does not exist, we route the request through index.php.
The application is then responsible for decided on the response - where its a web page, an api request, a 404 error response, or anything else.
Instead, in our htaccess or web conf files, we can declare:
# Instead of this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
#Use this:
FallbackResource /index.php
This will do the same thing as the popular rewrite rules. See the docs for more info, or this post.