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.

I use IIS7. how do i config it so that if the user types www.serverfault.com it redirects to serverfault.com like on this site?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

There are 2 good ways to do this in IIS7. URL Rewrite is great if you have it installed. With that you can create a rule to redirect www to non-www. Another option is the HTTP Redirect feature in IIS.

To use the IIS HTTP Redirect (easiest method), do the following:

  • create a 2nd site with a host header binding of www.yourdomain.com
  • BE SURE to point it to a different path on disk since in IIS Manager updating the HTTP Redirect will update your web.config file which you don't want to update for your main site. Just point to a deadend folder since it isn't used for anything else for reading the web.config file.
  • For your www site, turn on the HTTP Redirect and set the value to http://yourdomain.com. Set the status code to 301 (permanent)
share|improve this answer
    
@Scott: Thanks for the insight. i thought host headers and the appropriate DNS records were all that was required. Thanks for clearing it up for me. –  joeqwerty Nov 25 '09 at 3:53
1  
@joeqwerty. Often times it is all that is needed. People don't usually mind having 2 domains (with and without www) pointing to the same site. It's getting more common now for people to ensure that only 1 domain name points to their site search engine positioning (SEO) reasons. –  Scott Forsyth - MVP Nov 25 '09 at 4:15
    
@Scott: well then i learned something new today... ;) –  joeqwerty Nov 25 '09 at 4:29

huh? do you mean that if the user types mydomain.com or www.mydomain.com that it goes to the same web site? if so, then you need to do two things:

  1. make sure your domain A record points to the ip address of the web server. make sure your www record points to the ip address of the web server (obviously).

  2. add host headers to the web site in iis7 for both url's. you'll want to add mydomain.com and www.mydomain.com as host headers on the web site.

share|improve this answer
    
type www.serverfault.com it goes to serverfault.com. but type serverfault.com it stays serverfault.com –  newBEE Nov 25 '09 at 2:53

Easiest solution is you can add bindings to domain. In iis select your site and in right pane in bindings section add binding;

www.example.com

example.com

share|improve this answer

Your Answer

 
discard

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