0


I have been trying to deploy my Angular 7 application to HTTPD Apache 2 Server. These are the steps I have taken:

  1. Setup a Virtual Host for my project
  2. Build --> ng build --prod
  3. Created and configured .htaccess as instructed here:

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

  4. Configured my app-routing.module.ts like this:

imports: [RouterModule.forRoot(routes ,{onSameUrlNavigation: 'reload'})]

My main page works but when I try to navigate through other routes e.g. http://myhostname/users/crud, it won't work anymore. Is there something I have missed here?

Thanks.

Artanis Zeratul
  • 963
  • 2
  • 14
  • 40
  • most probably you need to set `base href` in your angular app. – jcuypers Mar 18 '19 at 05:30
  • Have you took a look at this problem : https://stackoverflow.com/questions/34816025/angular2-routing-deep-linking-not-working-with-apache-404 ? – Wandrille Mar 18 '19 at 07:08
  • 1
    Thanks @Wandrille. But I gave up on this since I am not an active PHP developer right now. I tried your answer but I used Springboot with embedded apache tomcat instead and I handled the routing via Zuul and application.properties. And it worked fine :)! – Artanis Zeratul May 02 '19 at 00:49

1 Answers1

1
Build --> ng build --prod --baseHref=/users/crud/

instead of

Build --> ng build --prod

Try the above code. That code work for me.

  • Thanks @user2455218. But I gave up on this. I tried your answer but I used Springboot with embedded apache tomcat instead and I handled the routing via Zuul and application.properties. And it worked fine! – Artanis Zeratul May 02 '19 at 00:48