Redirect your azurewebsites.net URL to your custom domain URL

If you’ve attached a custom domain to your Azure Websites setup, you probably want people and search engine crawlers to use the custom domain URL instead of the free azurewebsites.net URL. You can setup your application’s web.config to include the following.

Add the following to the system.webServer section of your web.config, but make sure you replace the “yourdomain” text with your own domain information.

    
      
        
          
          
            
          
          
        
        
          
          
            
            
          
          
        
      
    

Add a comment

Your email address will not be published. Required fields are marked *

Comments

  1. Jay

    Useful information. Worked for me. Thanks.

    Reply
  2. Alam

    This works, but generate another problem. if you use your custom domain you get an error: This Connection is Untrusted

    Reply
    1. Justin

      Hi Alam. That error makes me think that your domain’s SSL certificate isn’t setup properly. Can you give me some more info?

      Reply
  3. Jonathan

    Thanks for the info. I’m still new to this so this might be an obvious question but what is the second rule “WWW Rewrite” for?

    Reply
    1. Justin

      Hi Jonathan. The WWW Rewrite will force a non-www URL to redirect to the www equivalent. For example, if someone went to “example.com” it would redirect to “www.example.com”. But the rule has two “negates” which will not fire for an already www URL and a localhost URL (for dev purposes).

      Reply
  4. Hatch

    Really take care with that “.azurewebsites.net” redirect if you have set up a default Traffic Manager profile, because it will ping root of “.azurewebsites.net” and by default expects a status code 200 as response but now gets a 301, thinking your site is down and redirects all traffic to your fallback endpoint.

    Configure your Traffic Manager to ping a path that is not affected by the redirect.

    Reply
    1. I’d like to echo this comment as it is a really important consideration. There are a number of Azure services that will only ever ping “.azurewesites.net” and will NOT follow redirects, making them ineffective. Slot swap warmup requests, AlwaysOn pings are some examples. Be careful with this.

      Reply