Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache with Angular2 - 404 Not Found

I have deployed an Angular2 application on an AWS server with Bitnami image. The application is served by Apache (configured with a virtual host on port 8080) and works fine as long as I start from index.html. If I want to access a different page (which has been configured in the RouteConfig) I get a 404 not found error. Here is the configuration of the virtual server:

Listen 8080
<VirtualHost _default_:8080>
  DocumentRoot "/opt/bitnami/apps/MyApp"
<Directory  "/opt/bitnami/apps/MyApp">
Options All
Require all granted
</Directory>
</VirtualHost>
like image 320
Picci Avatar asked Apr 15 '26 02:04

Picci


1 Answers

Add .htaccess file to your root folder. I'm using this:

# BEGIN ServeStatic

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

# END ServeStatic  

it serves index.html for all requests that would cause 404...

like image 126
Sasxa Avatar answered Apr 17 '26 16:04

Sasxa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!