Search code examples
angularpathapache2ngroktunnel

ngrok doesn't work with path in browser (Angular Webserver)


I'm currently developing a website with Angular and I'm hosting it on my RaspberryPi with Apache2. I'm using a ngrok tunnel to access the server from the internet.

This works perfectly fine as long as I open it via the root path and just click my way through the application. The problem is that everytime I reload the page or try to access a page e.g. '/home' manually, the Server returns 404 'The requested URL was not found on this server'. On localhost everything works, so it can't be Angular.

Does anybody know why this is happening and how to fix it? Maybe there is something wrong with ngrok or Apache?

Many thanks in advance!


Solution

  • Problem solved!

    I added a .htaccess file to the Angular assets to redirect every request to index.html

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      # Redirection of requests to index.html
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^(.*) index.html [NC,L]
    </IfModule>