I have an Apache site with a mix of ReactJS SPA (dynamic) routing and static HTML files. It's common to see rewrite strategies that direct all requests on non-existing files to /index.html
at the root of the site.
What I need is similar, but when a request comes in to a directory, it needs to first search each directory for a (default) index.html
file.
So if there is a request for:
www.example.com/this/directory/
It will first look for:
www.example.com/this/directory/index.html
...before redirecting to www.example.com/index.html
where the React app resides.
The partial solution I have currently is:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
...which does redirect to the root index.html
, but does not first look for an index.html
file in the subdirectory.
The static HTML portion of the site is vast, so reworking to fix all the HREFs at this point is a no-go.
I've looked around, but can't find an answer to this amongst the noise in my searching.