Redirect non www to www and getting 404 on an Azure Linux App Service

NM 0 Reputation points
2023-06-24T16:43:34.5966667+00:00

I have an Angular app that uses API calls from my .NET 6 API.

My issue is when I deploy my app into my Linux Web App. When my page loads in works fine but as soon as I click to another link it displays a 404 error. There is also an issue with redirecting non www to www in the url. For example https://www.example.com works but not https://example.com

I understand that this is because I am using Angular which is a SPA. I understand that on a Windows App Service, we configure this on the web.config. I've searched for days but could not find a solution which applies to a Linux Web App.

My questions are:

  • How do I configure my Linux app service to redirect non www to www?
  • How do I avoid the 404 error when navigating throughout my site on a Linux app service?
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,993 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,286 Reputation points Microsoft Employee Moderator
    2023-06-27T15:00:42.5+00:00

    For rewriting URLs on Linux, you can reference NGINX Rewrite Rules for Azure App Service Linux PHP 8.x - (azureossd.github.io). I realize its PHP, but the base image is Linux based so the principals are still applicable.

    When I've hit 404 errors like you have, my issue was with the route itself. In my markup, I did not have the correct path. You could have same thing but use the browser developer tools Networking tab to confirm. If not, could you provide additional context on your environment the type of URLs that are ending up 404, e.g.

    • Are they links within the SPA or SPA to API?
    • Is your SPA standalone or a front-end hosted within an ASP.NET backend
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.