skip to Main Content

I have created a website on Azure, and linked it with custom domain name(CNET).

Now, when I look at domains on website configuration on Azure panel I see both www.mywebsite.com , and default mywebsite.azurewebsites.net. Both of these domains work fine and I can access website using any of these.

How can I remove mywebsite.azurewebsites.net domain? Does having both of these domains affect SEO?

EDIT*
Thanks for answers, I am trying to enable a 301 redirect, but it is not working. I have added this to web.config file (“example” being my actual site name)

<system.webServer>
<rewrite>
  <rules>
    <rule name="SEOAzureRewrite" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^example.azurewebsites.net$" />
      </conditions>
      <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
</system.webServer>

I run the website but nothing happens. I can still access the mysite.azurewebsites.net address.

3

Answers


  1. Chosen as BEST ANSWER

    Since I couldn't set up the url rewrite in web.config, I created global filter to check for azure url and display error if so. Here is the filter, and I added a new view in my error pages for this purpose that just says "Page doesn't exist" to avoid indexing by search engines. Think this will solve possible duplicate indexing issues.

        public override void OnResultExecuting(ResultExecutingContext context)
        {
            if (context.RequestContext.HttpContext.Request.Url != null)
            {
                string path = context.RequestContext.HttpContext.Request.Url.AbsoluteUri;
    
                if (path.ToLower().Contains("mywebsite.azurewebsites") && !path.ToLower().Contains("error/oldazuresubdomainredirect650"))
                {
                    throw new HttpException(650, "Azure legacy");
                }
            }
        }
    

  2. there is no problem in having both domains pointing to your website.

    for SEO, you must do 301 redirect from mywebsite.azurewebsites.net to http://www.mywebsite.com.

    It has to be 301 redirect. As this will tell the search engines to always index http://www.mywebsite.com

    Login or Signup to reply.
  3. You can create a url rewrite rule to do exactly that

    You just need to add a redirect rule to your site’s web.config file. You can do that by adding the following rewrite rule to the web.config file in your wwwroot folder. If you don’t have a web.config file, then you can create one and just paste the text below into it, just change the host names to match your site’s host names:

    <configuration>
      <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>  
    </configuration>  
    

    The above is all you need to do to get it to work. If you’d like to better understand what exactly that code does and why it works, there’s a detailed writeup at https://zainrizvi.io/blog/block-default-azure-websites-domain/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search