1

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

3

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>
  • Bummer on Godaddy, but thanks for the info! If I don't do this, will it affect my PageRank? – Greg Jul 16 '09 at 13:24
  • 1
    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. – Adam Brand Jul 16 '09 at 14:36
  • 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. – David Apr 29 '16 at 17:55
0
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.

  • 2
    not sure that .htaccess is going to be too useful in IIS7.. – Jeff Atwood Apr 26 '10 at 5:19
0
<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

If you're using a GoDaddy virtual dedicated server or dedicated server then you can set this up in IIS.

I'm trying to find a way of doing this on GoDaddy using a non-dedicated server. I have to move some content about and want to maintain pagerank.

0

Updated Answer. This is a real late reply, but since this question came up in google, while I was looking for a solution, I found that you can easily do this using godaddy's domain tools.

These steps assume that your www name is already working.

In godaddy, view your list of domains. Click the check mark next to the domain you want to forward to www. Click the "Forward" button on top, then "Forwarding Domains". If you don't have any forwarding credits, you can "buy" them for free, by clicking the "Buy More" link. Next click the "Add one now" link and add your domain name prefixed with www:

enter image description here

Then give it time to propagate (up to an hour).

-2

You should have the root domain be your main domain, and set your CNAME record for WWW to point to '@'. Then all www.example.com requests will resolve to example.com.

  • You've gone the wrong way. He wants to go from domain.com to www.domain.com – Christian Payne Mar 28 '11 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.