Angular 4 App in Apache

0

I would like an example of htaccess to use in my Apache.

The scenario is as follows:

I have an application in Angular 4 that needs to run on a separate back-end server. I build using the ng build command (for some internal problems I do not use ng build --prod) and put the generated files in the htdocs / app folder.

In need of the project, I need to use relative urls so that apache can redirect.

Ex: The url that would be link , should be api / app / something.

I already searched Google and Stackoverflow, and none of the suggested solutions for redirection worked. My htacces looks like this:

RewriteEngine on

RewriteRule "api/app" "http://localhost:8080/app/rest/$1" [P]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) index.html [NC,L]

The idea is that when I make a request on my angular server, it sees the api / app path and redirects to localhost. I already have this proxy running on dev via angular-cli, but I need to use this also in apache.

Another thing is that when I use my routes without the "#", it can not reload. If I get out of root ('/') it can follow the route, but when I update em it gives 404 error.

I hope it was clear. Thanks!

P.S. Not Apache's handle, so I'm picking it up like this.

; D

    
asked by anonymous 13.09.2017 / 21:39

2 answers

0

Francisco:

I recently had this difficulty.

When performing the build, you can not do it using the ng build command --env = prod?

And check the generated html file, the default href of the document by default is as root "/". You need to specify the appropriate path for your folder on the apache server.

    
24.09.2017 / 21:06
0

ng build --prod --base-href / app /

If you use gitbash then it is: ng build --prod --base-href // app /

I hope to be your solution.

    
18.02.2018 / 03:36