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

If I type in domain.com and also www.domain.com, they both show the very same internet site, yet show various links in the address bar. I would certainly such as site visitors and also internet search engine that simply type "domain.com" to be rerouted to "www.domain.com".

I'm making use of IIS 7 on a godaddy organizing account. Just how do I redirect all ask for "domain.com" to "www.domain.com"?

I have the default DNS arrangement, "domain.com" as my "A record" and also the cname "www" indicate my "A record".

1
2022-06-07 15:16:40
Source Share
Answers: 3
<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
    if (Request.Url.Host.Equals("domain.com"))
    {
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location","http://www.domain.com");
    }
}
</script> 
0
2022-07-22 14:05:44
Source
RewriteCond %{HTTP_Host} ^(www\.)?secondary-domain1\.com$ [NC]
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [L,R=301]

You could also put something like this in your .htaccess file so every body reacts the same to it, not just Google.

0
2022-07-08 04:57:37
Source

You can not do this with the GoDaddy domain name monitoring devices, and also I do not assume you can from the web server devices either. If you actually desire this attribute, you can do it dynamically with ASP.Net by creating some code similar to this (thinking you have a default.aspx web 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>
3
2022-06-07 15:50:12
Source