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

8,642

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>
Share:
8,642

Related videos on Youtube

Greg
Author by

Greg

When evaluating a new technology, remember that novelty is its own reward

Updated on September 17, 2022

Comments

  • Greg
    Greg over 1 year

    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".

  • Greg
    Greg almost 15 years
    Bummer on Godaddy, but thanks for the info! If I don't do this, will it affect my PageRank?
  • user1124702
    user1124702 almost 15 years
    It shouldn't. If you want to be sure, you can use the Google for Webmasters tools and tell Google to only pay attention to the www. Also, to be sure, make sure inbound links use www.
  • Bill
    Bill about 14 years
    not sure that .htaccess is going to be too useful in IIS7..
  • David
    David about 8 years
    This should be handled at the web server level (that is, in IIS), not in the application itself. You do not want to write your code in such a way that it cares what the URL is.