Redirect your 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 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.

7 thoughts on “Redirect your URL to your custom domain URL

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

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

  2. 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?

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

  3. Really take care with that “” redirect if you have set up a default Traffic Manager profile, because it will ping root of “” 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.

    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 “” and will NOT follow redirects, making them ineffective. Slot swap warmup requests, AlwaysOn pings are some examples. Be careful with this.

Leave a Reply

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