Change the VirtualHost configuration (typically found in /etc/httpd/conf.d\vhosts.conf
) by adding the following Rewrite* lines:
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/httpd/example.com
<Directory "/var/www/httpd/example.com">
...
RewriteEngine On
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
This tells Apache to serve any files that exist, but if they don’t exist, just serve /index.html
rather than a 404: not found
.
-
Apache Reference: Configuring Apache Virtual Hosts
-
react-router
History Reference: Configuring Your Server
Complete answer gratefully stolen from here
Edit: ‘On’ need to be uppercase in current apache version