Tuesday, January 18, 2011

redirect to domain without www

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?

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

    From joeqwerty
  • I believe you want edit your zone's DNS records and not mess with IIS. Add a CNAME record named WWW to point to yourdomain.com. So www.yourdomain.com would resolve to yourdomain.com and leave out the WWW.

    James Deville : as Scott mentions, this will give you 2 sites with the same content with 2 urls. It also won't redirect. www.foo.com will go to www.foo.com and foo.com will go to foo.com. OP wanted www.foo.com to redirect the browser to foo.com.
    Dscoduc : This doesn't force the user to choose www.domain.com or domain.com... Unless you are using a reverse proxy solution , like ISA, IIS is exactly the place where you would make this change.
  • 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)
    joeqwerty : @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.
    Scott Forsyth - MVP : @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.
    joeqwerty : @Scott: well then i learned something new today... ;)

0 comments:

Post a Comment