简体   繁体   中英

Redirect to naked domain (no www) on Azure

I have a shared server website on Azure, and I have my DNS setup with the help of my domain host.

I have an A record pointing to the IP provided by Azure (from the Control Panel), and I have two CNAME records pointing to the Azure url, one with www and one without.

However, I want the www to forward to the naked domain, and right now I'm getting a 404 on Azure.

How do I configure Azure to redirect to the naked domain?

From what you are saying, I believe there is an error in the DNS records you created.

What you need to do is

  • Create a CNAME record of www to your .azurewebsites.net

OR

  • Create a CNAME record of awverify.www to awverify..azurewebsites.net

This is required to veify that you actually own the domain you are attempting to use. You will also need to keep the A record pointing to the virtual IP address of your web site.

Once the DNS configuration is Ok, you need to enable the domain in Azure.

All required steps are documented here: http://azure.microsoft.com/en-us/documentation/articles/web-sites-custom-domain-name/

Updated 20140701

Try adding the following additional CNAME record:

  • awverify.yourdomain.com pointing to awverify..azurewebsites.net

Failing other solutions, I implemented a redirect in my base controller by extending OnActionExecuting as follows:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    var url = System.Web.HttpContext.Current.Request.Url.OriginalString;
    var baseUrl = System.Web.HttpContext.Current.Request.Url.Authority;
    if (baseUrl.ToLower().Contains("www.mywebsite.com"))
    {
        filterContext.Result = new RedirectResult(url.Replace("www.mywebsite.com", "mywebsite.com"));
        return;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM