3

I am creating ng build --prod in angular 6, and deploying it to the Apache Server. Build works fine but when iam refreshing the page it shows "Not Found". Also iam creating .htaccess file in my root folder...

RewriteEngine On  

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]  
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d  
RewriteRule ^ - [L]


RewriteRule ^ /index.html  
fahad ali
  • 154
  • 1
  • 4
  • 14
  • Take a look at that : https://stackoverflow.com/questions/18406156/redirect-all-to-index-php-htaccess –  Aug 06 '18 at 11:54

2 Answers2

1

One of the possible reason could be that you are deploying in a sub-directory.

Change this line

RewriteRule ^ /index.html  

to

RewriteRule ^ /subDirectoryName/index.html  

Hope this helps.

Faheem
  • 1,105
  • 11
  • 28
-2

You should read the docs explaining how to deploy an Angular app: Angular deployment.

Routed apps must fallback to index.html

Angular apps are perfect candidates for serving with a simple static HTML server. You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side.

If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have.

A routed application should support "deep links". A deep link is a URL that specifies a path to a component inside the app. For example, mysite.com/heroes/42 is a deep link to the hero detail page that displays the hero with id: 42.

There is no issue when the user navigates to that URL from within a running client. The Angular router interprets the URL and routes to that page and hero.

There are examples of configuration for several web servers.

Christian Benseler
  • 7,907
  • 8
  • 40
  • 71