Since you want to be able to provide one kind of response for directories, or paths that look like directories (e.g. /financing/terms
), and a different kind of response for files, then I believe the Files directive is what you're looking for.
I created a branch in a GitHub repo that has a Docker image with Apache and a sample single page app from Ember to demonstrate the solution. To test it out, clone the repo and checkout the fallbackresource
branch. From there, assuming you have Docker installed, follow the directions in the README. The server will start on port 80 so then you can visit http://localhost
. A screenshot of the SPA running is below.

Localhost redirects to http://localhost/rentals once the single page app kicks in and redirects. Notice the 404 in the network tab--there is a link to a non-existent JS file that is throwing a 404 instead of falling back to the index.html file.
This works due to the Files directive in the configuration file (viewable below and in the source for that branch).
# Map all SPA-looking routes to our single page app index file
<Directory ~ "^/[\w+\d+-]+">
FallbackResource /index.html
</Directory>
# Requests for files should return a real 404 and not fallback to the index.html page, though
<Files ~ "\.(js|css|gif|jpe?g|png)$">
FallbackResource disabled
ErrorDocument 404 "File not found"
</Files>
The Directory
directive uses a regular expression to match to word characters, digits, and hyphens so that routes you probably want mapped to SPA routes should fallback to the index.html file. However, individual file type requests do not fallback because the Files
directive disables the FallbackResource property.
Combining these two directives in your Apache config should give you the behavior you're shooting for.