can we remove/disable http://domain.azurewebsites.net domain after adding custom domain?

Henry Cruise 1 Reputation point
2021-10-29T05:43:48.15+00:00

we are facing the problem of double domain, first is from testing http://domain.azurewebsites.net and second is our custom domain. Problem is that after adding custom domain? the azurewebsites.net domain is still there and still works!

can anyone help regarding this matter?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,833 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 22,086 Reputation points Microsoft Employee
    2021-10-29T13:31:33.277+00:00

    @Henry Cruise , Thanks for the great question.

    Short Answer:
    Firstly, App service support HTTPS on *.azurewebsites.net domain name and the certificate is provided and owned by Azure.

    I understand the requirement of removing the default domain, but there is no way disable it. You could instead accomplish this by adding a rewrite rule (Or Redirect rule) to the web.config file in your wwwroot folder.

    {Yes, by default, http://domain.azurewebsites.net works even with custom domain added, and the site admins aware about the URL can access, but typically end users would not access this URL directly (unless explicitly shared). }

    Long Answer:

    Essentially, indicating IIS to take any request where the host name matches the RegEx pattern “^yoursite.azurewebsites.net$” and return an HTTP 301 response.

    The response will include the originally requested url, except it’ll be pointing to your custom “www.yoursite.com” domain instead. When the user’s browser reads that 301 response and the new url, it will automatically load that new url instead. It’ll even change the address the user sees in the address bar.

    <system.webServer>    
        <rewrite>    
            <rules>    
              <rule name="Redirect rquests to default azure websites domain" stopProcessing="true">  
                <match url="(.*)" />    
                <conditions logicalGrouping="MatchAny">  
                  <add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />  
                </conditions>  
                <action type="Redirect" url="http://www.yoursite.com/{R:0}" />    
              </rule>    
            </rules>    
        </rewrite>    
      </system.webServer>    
    

    Kindly see this blog for more information. Change the host names to match your site’s host names:

    OR:
    If your requirement fits, you could add condition to display ‘403’ error.

    <conditions>
    <add input="{HTTP_HOST}" pattern="^(.*?).azurewebsites.net$" />
    <action type="CustomResponse" statusCode="403" statusReason="Forbidden" />