I'm currently learning Angular-CLI for a Project. I succeeded in creating a simple little project with some routing Objects. In dev mode with ng serve, everthing works just fine. I can call the localhost:port in the browser and it works with the routing.
Routing when executed with ng server.
After a successful ng build -prod and moving all the stuff from the dist directory into my Server Folder (Apache24/htdocs), I start my Server and the main Side (mywebside) just works fine, the routing however does not... (i.e. localhost/about), instead I get a standart Error-Page as shown below:
Hope I was able to describe clearly what I did and where my problems are. I didn't posted any Code because I think the problem has to be else where.
Thank you for your help!
Manuel
Versions:
angular CLI: Beta.8 (latest)
(apache): 2.4.20
1 Answer 1
OK figured it out (with help from PierreDuc!)
You have to do 2 things:
- add a .htaccess file: (just like that no filename!) in the folder where your index.html File is saved, insert this code:
ErrorDocument 404 /index.html
- Edit the httpd.conf:
(you find the File in the Apache24/conf/ directory) search for the line:
<Directory "c:/Apache24/htdocs"> [...] -> in my Version of apache it is in line 244
a few lines further (after a few comments) you should find this line:
AllowOverride none -> in my Version of apache it is in line 264
change this line to
AllowOverride ALL
Thats it, now your Angular-CLI Website should work in the production build with routing objects
hope it might be helpful to other Developpers!
Thanks to PierreDuc!
Manuel
1 Comment
AllowOverride. Forgot about that one! Good find :)
index.html?RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html [L].htaccessin the same map as yourindex.htmlfile