I would like to configure my Apache web server to serve both a single page application, as well as a WSGI process. I can successfully serve the WSGI app at /api
using this config:
WSGIDaemonProcess myapp threads=5 user=apache
WSGIScriptAlias /api /var/www/html/myapp/setup/myapp.wsgi
As such, if a user hits /api/things
the JSON data from my WSGI app (flask) is sent over.
And my home index.html
file (which is served when the user hits /
) works when including this:
DocumentRoot /var/www/html/myapp/myappweb/public
However, when a user visits any route that does not start with /api
I would like my Apache web server to serve up index.html
. For example, if the user hits /things
or /things/42
I would like Apache to send them to index.html
instead of throwing a 404. (I am using redux-router to handle the client-side paths.)
I got this to work in my dev environment using the node live-server package with this flag:
live-server --entry-file=index.html
Additionally, I can use AliasMatch
to force all routes starting with /things
to show index.html
:
AliasMatch "^/things(/.*)?$" /var/www/html/myapp/myappweb/public/index.html
But what I really want is an AliasMatch
regex that forces all routes, except for anything starting with /api/
, to display index.html
.
Got it!
RewriteRule ^((?!\/[api|lib]).)*$ /var/www/html/myapp/myappweb/public/index.html
I needed to exclude both the api
dir as well as the lib
dir (where my js/css files are hosted).