7

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?

3 Answers3

6

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)
Scott Forsyth
  • 16,339
  • 3
  • 36
  • 55
  • @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 03: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 Nov 25 '09 at 04:15
  • @Scott: well then i learned something new today... ;) – joeqwerty Nov 25 '09 at 04:29
1

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

Xenon
  • 143
  • 1
  • 5
1

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.

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
  • type www.serverfault.com it goes to serverfault.com. but type serverfault.com it stays serverfault.com –  Nov 25 '09 at 02:53