redirect to domain without www

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)

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.


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