Configure Apache to redirect all requests 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.
Related videos on Youtube
Maruli
Updated on September 18, 2022Comments
-
Maruli almost 2 years
A CentOS 7 server is hosting a web application in
/var/www/someapp/public_html
. Requests formydomain.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 thatthe 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
? -
Maruli about 7 yearsI created a
.htaccess
file in theDocumentRoot
for the site in question, and put your exact syntax in it. I then typedsystemctl 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 inhttpd.conf
? -
Stephen Ostermiller about 7 yearsYou need to enable .htaccess by making sure that
AllowOverride All
is set for the directory in the Apache config files. -
Maruli about 7 years@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.
-
Stephen Ostermiller about 7 yearsYou can mark this one. It has the meat of it.
-
Maruli about 7 years@StephenOstermiller Meat alone gives people heart attacks, diabetes, and strokes. Vegetables are required. Your comments added the required vegetables.