DEV Community

Wai Liu
Wai Liu

Posted on • Originally published at on

Adding URL Rewrite for an Angular app deployed to Azure App Service

When deploying an Angular app onto Azure App Service, the routing is not going to work because Angular uses client side routing whereas by default, on an App Service, the routing is going to be server side. As a result, anything that's not the root domain is not going to point to index.html.

In order to fix this, you need to set up the App Service so that any route points back to index.html.

Azure App Service runs on IIS in the background so you need a web.config file to do a URL rewrite. To do this, you need to create a web.config file.





        <rule name="angularjs routes"


          <match url=".\*" />

          <conditions logicalGrouping="MatchAll">

            <add input="{REQUEST\_FILENAME}"

            matchType="IsFile" negate="true" />

            <add input="{REQUEST\_FILENAME}"

            matchType="IsDirectory" negate="true" />

            <add input="{REQUEST\_URI}"

            pattern="^/(api)" negate="true" />


          <action type="Rewrite" url="/" />






Enter fullscreen mode Exit fullscreen mode

Then you need to add it to the angular-cli.json file in the Assets bit


"$schema": "./node\_modules/@angular/cli/lib/config/schema.json",

"project": {

"name": "quiz"


"apps": [


"root": "src",

"outDir": "dist",

"assets": [





Enter fullscreen mode Exit fullscreen mode

When you run " ng build" now, it'll save web.config to the dist folder.

Discussion (0)