0
votes

I configured a custom domain for my Azure Web Site using CNAME records.

Everything works fine, except for the fact that I can access my site using both *.azurewebsites.net and *.com.

Isn't this a SEO issue, and can it be avoided so that I get *.com in both cases?

1

1 Answers

1
votes

You can try with simple url rewrite rule in your web.config file:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="MyHostNameRule">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://domain.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Basically, it says that if request host doesn't match specified pattern, just rewrite it to domain.com/... If you have access to the IIS, you can use Url Rewrite module there, where this code can be created through a wizard.

One hint: when developing app and testing on localhost:port, it will rewrite url. To avoid that, put this rewrite rule in Web.Release.Config, and of course deploy your app to Azure WebSite in Release mode! Only thing you need is add xdt:Transform to rewrite element:

<rewrite xdt:Transform="Insert">