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.

    <rule name="Redirect old-domain to new-domain" stopprocessing="true">
      <match url=".*">
      <add input="{HTTP_HOST}" pattern="^$">
      <action type="Redirect" url="{R:0}" appendquerystring="true" redirecttype="Permanent">
    <rule name="WWW Rewrite" enabled="true">
      <match url="(.*)">
      <add input="{HTTP_HOST}" negate="true" pattern="^www\.">
      <add input="{HTTP_HOST}" negate="true" pattern="localhost">
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendquerystring="true" redirecttype="Permanent">