What should be in .htaccess for Angular Universal app on Apache web host server?

1 answer

This question is related to the question I asked here, but this is a more specific question, so I'm asking it separately.

I have an Angular Universal web app that I want to deploy on an Apache web server. I installed pm2 to start the app and keep it alive. It's listening on port 4000. It shows no errors in the logs, but I'm getting a 403 when I go to the website.

I think something in the .htaccess file is incorrect or something needs to be configured in the httpd.conf file. I'm confused as to what exactly needs to be in those files, because several links/articles I've read show different configurations. Some say you only need the .htaccess file. Other say you also need to configure a virtual host in the httpd.conf file (which I can't reach, because I don't have root privileges on the server).

This is how the folder structure looks like:

domains     - appname.com         - public_html             - .htaccess             - browser                 - index.html                 - other files...             - server             - server.js             - package.json 

And this is my current .htaccess file, which should work for https and redirects to browser/index.html:

RewriteEngine On    # If an existing asset or directory is requested go to it as it is RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L]  RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}/browser/index.html 

I also tried this configuration which places a virtual host inside the .htaccess file, but that doesn't work.

To summarize my question: What exactly needs to be in the .htaccess file for Angular app to work? Is the virtual host tag supposed to by in the .htaccess as well or does that only work from the httpd.conf file?

Update

I contacted my web host. They said it's not possible to add the virtual host to the .htaccess file. So all I need is the redirect rewriteRule, taking https in consideration.

All answers to this question, which has the identifier 58528763

The best answer:

Together with my web host I got it to work. So what they put in the httpd.conf file were the proxy settings for both ports (80 for http and 443 for https). My app runs on port 4000 so that's why they had to add proxy settings to that port. The httpd.conf file now probably looks something like this:

<VirtualHost *:80>  ServerName domainname.com  ServerAlias www.domainname.com  <Proxy *>   Order allow,deny   Allow from all  </Proxy>  ProxyPreserveHost On  ProxyRequests Off  ProxyPass / http://localhost:4000/  ProxyPassReverse / http://localhost:4000/ </VirtualHost>  <VirtualHost *:443>  ServerName domainname.com  ServerAlias www.domainname.com  <Proxy *>   Order allow,deny   Allow from all  </Proxy>  ProxyPreserveHost On  ProxyRequests Off  ProxyPass / https://localhost:4000/  ProxyPassReverse / https://localhost:4000/ </VirtualHost> 

So you should add your domain name to the serverName and serverAlias variables and set the proxy to localhost:4000, or whatever angular is running on.

And I moved the .htaccess file to browser folder where my index.html is located and changed it to this:

<IfModule mod_rewrite.c>     RewriteEngine On      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d      RewriteRule ^.*$ - [NC,L]     RewriteRule ^(.*) /index.html [NC,L] </IfModule> 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data