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

how exactly can i specify that http://mydomain.com be rewritten to http://www.mydomain.com ? A

share|improve this question
Bit vague. More details would help elicit some answers. Do you mean that if the public type mydomain.com they should be redirected to mydomain.com ? –  Izzy Nov 27 '09 at 20:38
Seems clear to me... This would be handled with a rewrite rule. IIS has a rewrite module that will take care of this very easily. See Scott's answer for more details. –  Dscoduc Nov 28 '09 at 19:14

2 Answers 2

up vote 2 down vote accepted

To do a redirect from non-www to www using URL rewrite, you can:

  • Create a new rule
  • Set the "Using" to wildcards. You can use regex, but these instructions are for wildcards
  • Set * for the Pattern
  • Add a condition where {HTTP_HOST} matches mydomain.com
  • Set the action to "Redirect" with the URL as "http://www.mydomain.com/{R:0}
  • It's a 301 permanent redirect that you most likely need. Search engines prefer that.
share|improve this answer
An excellent helper site to learn about URL Rewriting can be found at learn.iis.net/page.aspx/461/… –  Dscoduc Nov 28 '09 at 19:19
That is a good site. Thanks @Dscoduc. I just blogged about this yesterday too, so here's a more detailed walkthrough for this particular situation weblogs.asp.net/owscott/archive/2009/11/27/… –  Scott Forsyth - MVP Nov 28 '09 at 23:02
this is what i did, however, i have one issue still. the the entire path is not being changed over, it goes mydomain.com/HomePage to mydomain.com. If I append {R:1} i get errors. btw difference btween {r:0} and {r:1}? –  zsharp Nov 29 '09 at 22:12
{R:1} should be the full path. If your pattern had multiple parts, like domain.(com|net) then you'll have results for {R:1} or others. You can use the "Test" mini-tools without URL Rewrite in IIS Manager to see the results. Make sure that you have a trailing / after your domain name in the redirect. –  Scott Forsyth - MVP Nov 29 '09 at 22:48
When you create the rule, you can select the "Canonical Name" rule template and it'll do all this for you. –  Eric Falsken Jan 21 '12 at 7:53

If you want the public that type http://mydomain.com into their browsers to be redirected to http://www.mydomain.com then it's quite straightforward.

Firstly you need to add anther A record into your public DNS zone to point mydomain.com to the same IP address as the www A record.

Then you need to configure the host headers for the site in IIS to respond to mydomain.com as well as www.

As good practice (it's been a while since I worked with webservers) in the past we've done this for www, ww, and w to help with typos.

share|improve this answer
Web client asks for domain.com and you want them to go to www.domain.com... Not really a DNS function... –  Dscoduc Nov 28 '09 at 19:20

Your Answer


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.