The default App Service domain xxx.azurewebsites.net cannot be changed or removed. It is there to stay. If you don't want users to access it, your option is to redirect the azurewebsites.net requests to your custom domain. 

If your Web App is running on Windows then you can achieve this with a web.config placed in the wwwroot directory.

Table of Contents

Redirect azurewebsites.net

There place the following code under <configuration>/<system.webServer>/<rewrite>/<rules>. Change the CAPITALZED webappname and custom domain below with your own values.

<rule name="Redirect azurewebsites.net to Custom Domain" stopProcessing="true">
  <match url=".*" />
  <conditions>
  <add input="{HTTP_HOST}" pattern="^(.*?)\.azurewebsites\.net$" />
  </conditions>
  <action type="Redirect" url="https://CUSTOMDOMAIN.COM/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

This is the complete web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect azurewebsites.net to Custom Domain" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(.*?)\.azurewebsites\.net$" />
          </conditions>
          <action type="Redirect" url="https://CUSTOMDOMAIN.COM/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

 

Tip!

If these rules give you a result of "Too many redirects" check if you have some other service before your Web App, such as Application Gateway or Azure Front Door. Another reason could be a redirect rule from outside of the web.config. Such as HTTPS Only on your Web App TLS/SSL Settings or a redirection coming from your applicaiton code which causes additional redirects

Block azurewebsites.net

Sometimes you might not be happy with just a redirect. If you want to just block/drop the requests coming to .azurewebsites.net use the following:

AbortRequest will drop the request but in Azure App Service this would be a 502 IIS like page, if 403, it will be a "You do not have permission to view this directory or page."

The good part about this is that this is domain agnostic. You just put it to any Azure web app out there and it will work. Now, if you have other rules after, they might interere so be cautious.

<rule name="Block azurewebsites.net" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(.*?)\.azurewebsites\.net$" />
   </conditions>
   <!--<action type="AbortRequest" />-->
   <action type="CustomResponse" statusCode="403" statusReason="Forbidden" />
</rule>

 

Redirect to azurewebsites.net in Linux

In Apache you can achieve this with putting a redirect rule in the .htaccess file. Try the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^WEBAPPNAME.azurewebsites.net$ [NC]
RewriteRule ^(.*)$ https://CUSTOMDOMAIN.COM/$1 [L,R=301]