Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

6 Answers 6

up vote 3 down vote accepted

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|improve this answer
    
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
1  
Thanks! I'd upvote twice if I could. –  Greg Jul 16 '09 at 15:43
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.

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

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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