Iis – 301 redirect root domain to www subdomain on godaddy windows hosting account

godaddyiisiis-7redirect

If I type in domain.com and www.domain.com, they both show the same website, but show different urls in the address bar. I'd like visitors and search engines that just type "domain.com" to be redirected to "www.domain.com".

I'm using IIS 7 on a godaddy hosting account. How do I redirect all requests for "domain.com" to "www.domain.com"?

I have the default DNS setup, "domain.com" as my "A record" and the cname "www" points to my "A record".

Best Answer

You can't do this with the GoDaddy domain management tools, and I don't think you can from the server tools either. If you really want this feature, you can do it dynamically with ASP.Net by writing some code like this (assuming you have a default.aspx page):

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
   if (Request.Url == "http://mysite.com")
   {
      Response.Status = "301 Moved Permanently";
      Response.AddHeader("Location","http://www.mysite.com");
   }
}
</script>