Set up URL rewrite for Linux based Azure App Service

Tenanana-7634 61 Reputation points
2022-07-01T09:34:59.193+00:00

Hi,
We are trying to configure URL rewrite for our application that is hosted on Azure App Services, however we cannot get it to work. At this moment, even simple test rewrite rules don't seem to be working.
For example:
It's a .net 6 application hosted on Linux-based App Service.
Could you please let me know, what are the steps required to enable rewrite for Linux-based App service applications?
Let me know if any additional information is needed.
Thank you.
Tena

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,207 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. JasonPan - MSFT 4,376 Reputation points Microsoft Vendor
    2022-07-06T07:22:05.207+00:00

    Hi @Tenanana-7634

    ajkuma-MSFT 's comment is useful. I'll summarize and add a little bit about the way to achieve this requirement using the web server configuration file.

    Because asp.net core is cross-platform, it is most convenient to use middleware to implement url rewrite, and it is also convenient to deploy.
    But if you know the type of web server, that's also achievable. When we create an azure web app, use F12 to check the information of the webserver, and then choose to add the corresponding file.

    Different servers use different configuration file types as follows:

    IIS : using web.con fig
    Nginx : using .conf
    Apache : using .htac cess


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Jason

    1 person found this answer helpful.
    0 comments No comments

  2. ajkuma 22,521 Reputation points Microsoft Employee
    2022-07-04T19:44:27.557+00:00

    @Tenanana-7634 , Apologies for the delay from over the weekend.
    Azure App Service on Linux images are now bundled with NGINX instead of Apache.

    There are couple of approaches to handle a Rewrite operation: in app middleware and URL Rewriting Middleware in ASP.NET Core in the code.
    Kindly check this discussion thread.

    Also, checkout this doc Host ASP.NET Core on Linux with Nginx for more details.

    sample-webconfig.txt

    -After to incorporate the changes, you may try to isolate, see if it works locally fine.
    -I have also added additional tags to receive insights from the targetted SMEs.

    0 comments No comments