A CentOS 7 server is hosting a web application in /var/www/someapp/public_html. Requests for mydomain.com get served the file located at /var/www/someapp/public_html/index.html. The user can then navigate to several browser-routes that are defined in the JavaScript web application. However, when the user refreshes the browser from one of those UI-routes, apache replies with a message indicating that the requested url is not found on the server.

What specific config settings need to be changed in order for all routes sent to apache to be redirected to index.html?


I do mine with a .htaccess file. In the DocumentRoot for the site, I create the .htaccess file and it in goes

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

Per @StephenOstermiller 's comment below, you also need to make sure that AllowOverride All is set in the Directory stanza as well. While mine is set up that way, I forgot to add that in the post since it is part of my default config.... so @StephenOstermiller gets the credit for that part.

| improve this answer | |
  • I created a .htaccess file in the DocumentRoot for the site in question, and put your exact syntax in it. I then typed systemctl restart httpd.service, and I waited a couple minutes. Then I reloaded the web site and refreshed one of the views, only to have the same problem persist. What else do I need to change? Perhaps something else in httpd.conf? – CodeMed Jun 19 '17 at 23:15
  • 1
    You need to enable .htaccess by making sure that AllowOverride All is set for the directory in the Apache config files. – Stephen Ostermiller Jun 20 '17 at 12:02
  • @StephenOstermiller Your suggestion enabled this to work. Therefore, if you write up an answer, I would be happy to mark it as accepted and +1. – CodeMed Jun 20 '17 at 18:46
  • You can mark this one. It has the meat of it. – Stephen Ostermiller Jun 20 '17 at 18:52
  • @StephenOstermiller Meat alone gives people heart attacks, diabetes, and strokes. Vegetables are required. Your comments added the required vegetables. – CodeMed Jun 20 '17 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.