Azure App Service Redirect

Mig Fimi 6 Reputation points
2021-09-27T17:38:16.223+00:00

Hello,

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 myappname.azurewebsite.net 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"?> 
<configuration> 
  <system.webServer> 
    <rewrite> 
      <rules> 
        <rule name="Redirect default azure subdomain" stopProcessing="true"> 
          <match url="(.*)" /> 
          <conditions logicalGrouping="MatchAny"> 
            <add input="{HTTP_HOST}" pattern="^myappname.azurewebsites.net$" /> 
          </conditions> 
          <action type="Redirect" url="https://mydomain.com/{R:0}" /> 
        </rule> 
      </rules> 
    </rewrite> 
    <handlers> 
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> 
    </handlers> 
    <aspNetCore processPath="dotnet" arguments=".\ComingSoon.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> 
  </system.webServer> 
  <system.web> 
    <compilation debug="true" /> 
    <httpRuntime /> 
  </system.web> 
  <appSettings></appSettings> 
</configuration> 
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,914 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. ajkuma 22,416 Reputation points Microsoft Employee
    2021-09-28T09:49:54.937+00:00

    @Mig Fimi , 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 *.azurewebsites.net 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.

    1 person found this answer helpful.

  2. Pierre-Luc Giguere 1,076 Reputation points
    2021-09-27T19:12:36.197+00:00

    Hello,

    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 ?

    135666-image.png