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.

3
  • most probably you need to set base href in your angular app. Commented Mar 18, 2019 at 5:30
  • Have you took a look at this problem : stackoverflow.com/questions/34816025/… ? Commented Mar 18, 2019 at 7: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 :)! Commented May 2, 2019 at 0:49

1 Answer 1

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

instead of

Build --> ng build --prod

Try the above code. That code work for me.

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.