1

I can deploy Angular to Azure Web Apps on Linux service plan and it works fine when hitting {myapp}.azurewebsites.net/index.html

I can navigate inside the app as expected.

When hitting the root {myapp}.azurewebsites.net it just displays the hostingstart.html.

It does not help to remove the hostingstart.html as suggested in some articles.

If I try to hit a sub page url directly (like {myapp}.azurewebsites.net/mypage) then I get an error : Cannot GET /mypage (this works when I run locally)

I suspect that i need to setup a default page, but i cannot find this anywhere in the Application Settings in the Azure Web App. (I think this is only available on Windows service plans - not on Linux Service Plans).

How do i deploy properly to Linux App Service for this to work ?

I have found a lot of articles on the issue, but they all seem to cover Windows App Service Plan.

TechnoCowboy
  • 344
  • 2
  • 15

1 Answers1

2

You need to add URL rewrite rules to the Apache server so that any page request gets redirected to Angular's index.html

Paste this into your root .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

(Source: https://github.com/angular/angular/issues/11884#issuecomment-288852433)

EDIT: If using a node.js backend, see this SO answer for reference: https://stackoverflow.com/a/34864585/235648

Aviad P.
  • 32,036
  • 14
  • 103
  • 124
  • Thanks for your help, but that didn't work. A "service httpd status" reveals that apache is not running. I believe it is node.js that is being used to serve. – TechnoCowboy Nov 14 '18 at 23:08
  • @TechnoCowboy then you must apply the same logic to node.js. One option is to trap 404 requests and then route them to Angular's `index.html` - see this SO answer: https://stackoverflow.com/a/34864585/235648 – Aviad P. Nov 15 '18 at 06:36
  • Thanks. But I can't get it to work. Dockerized the app using NGINX as base image. Now it works. – TechnoCowboy Nov 25 '18 at 08:04