MigFimi-3023 avatar image
0 Votes"
MigFimi-3023 asked ajkuma-MSFT answered

Azure App Service Redirect


I have modified the web.config on my azure app service B1 Plan to add a 301 redirect and it is absolutely not working. I want to redirect the default domain.

I have spoken with tech support and they advised me to ask this here.

My web.config content that is currently on the server is below (I have removed my actual domain for security). Please help.

 <?xml version="1.0" encoding="utf-8"?> 
         <rule name="Redirect default azure subdomain" stopProcessing="true"> 
           <match url="(.*)" /> 
           <conditions logicalGrouping="MatchAny"> 
             <add input="{HTTP_HOST}" pattern="^$" /> 
           <action type="Redirect" url="{R:0}" /> 
       <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> 
     <aspNetCore processPath="dotnet" arguments=".\ComingSoon.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> 
     <compilation debug="true" /> 
     <httpRuntime /> 
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PierreLucGiguere-5297 avatar image
0 Votes"
PierreLucGiguere-5297 answered ajkuma-MSFT commented


Thanks for the idea, it didn't work for me either in the beginning but I figured out my issue. Let's hope it's the same for you.

Did you add "web.config" to the Default documents in the App service and made sure no other file gets loaded first ?


image.png (54.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you. I actually do not hav that Default Documents tab. I have Application Settings, general Settings, Path Mappings but not the other.

I am on a Linux plan if that matters. Interesting.

0 Votes 0 ·

Just to clarify on this, "Default Documents" is available only on Windows WebApp and not on Linux WebApp at this time.

0 Votes 0 ·
ajkuma-MSFT avatar image
1 Vote"
ajkuma-MSFT answered

@MigFimi-3023, Thanks for posting the question here.

Just to confirm, Is this a Windows or Linux WebApp? What exactly happens (any specific errors via browser network trace)? Are you running App Services behind an Azure Application Gateway?

Hope you’d a chance to see the suggestions by PierreLucGiguere-5297, just adding to it.

So, the first part of your config, you’re redirecting the default * domain to a custom domain (so, ensure the CNAME record is added appropriately). Also, please see this blog by Zain Rizvi for the detailed steps.

Ensure that the web.config is added in the root.
All other deployment methods in App Service writes to D:\home\site\wwwroot in your app (or /home/site/wwwroot for Linux apps).

By default, users can access your app using HTTP. You can redirect all HTTP requests to the HTTPS port.
On Azure Portal, in your WebApp, in the left navigation, select TLS/SSL settings. Then, in HTTPS Only, select On.

If you’re using Application Gateway, please see this blog for more info.
I have also reached out you privately requesting on the support ticket that you'd mentioned.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


It is a linux web app. No errors are shown and the app service is not behind azure application gateway. I definitely followed the blog by Zain Rizvi and its instructions, this link was sent to me by the Microsoft Chat agent in the Azure help center (I did a live chat).

The web.config is in fact in the root, as a matter of fact, the contents that I placed in my question was retrieved directly from the wwwroot folder on the server to ensure I gave accurate info.

There was no support ticket, I went into the online chat for azure and after being unable to help, directed me to this Q&A system, I sent them the link and they then said they would escalate it internally. That's all the info I have.

0 Votes 0 ·

MigFimi-3023, Thanks for the follow-up and sharing all the details. sorry! the issue still persists.

Take a fiddler and if you see the response header has the Server as Kestrel, and if it’s neither the Nginx nor Apache then try URL rewriting via the middle layer -needs to be used as per the aspnet URL rewriting doc

See this sample -
-it illustrates usage of ASP.NET Core URL Rewriting Middleware. The app demonstrates URL redirect and URL rewriting options.
-ASP.NET Core URL Rewriting Sample AddRedirectToHttpsPermanent() -for 301

Kindly let us know if the issue still persist, I'll follow-up with you further to fetch more details about your WebApp and subscription details privately/offline; for further investigation.

0 Votes 0 ·