Skip to main content
1 of 4
CodeMed
  • 5.4k
  • 50
  • 111
  • 152

Redirect all non-root routes to index.html on Amazon Linux 2 and Apache

An Amazon Linux 2 instance is using Apache to host an Angular 7 app.

What specific syntax do I need to use in order to ensure that requests to Apache for all non-specified routes get redirected to the index.html located in the DocumentRoot?

For example, if a remote web browser requests mydomain.com/randomCharacters, I want Apache to return index.html the same way that Apache would respond to a request to mydomain.com with index.html.

(In this case, DocumentRoot is a directory entitled /var/www/mydomain.com/public_html).

I would like to use RedirectMatch inside of a VirtualHost block to keep the configuration as clean as possible. Here is what I have in mind. How does the following need to be modified?

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    DocumentRoot /var/www/mydomain.com/public_html
    ErrorLog /var/www/mydomain.com/error.log
    CustomLog /var/www/mydomain.com/requests.log combined
    RedirectMatch "What goes here?"
</VirtualHost>
CodeMed
  • 5.4k
  • 50
  • 111
  • 152