Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web site (hosted on IIS 7.5) that has bindings to four URLs. Something like:

  1. www.example.com
  2. example.com
  3. www.example.net
  4. example.net

What I would like to accomplish using URL Rewrite is that:

  1. Surfing to www.example.com will auto redirect to example.com (and return 301)
  2. Surfing to example.net will auto redirect to www.example.net (and return 301)

I tried using the URL Rewrite (I have no experience using this feature) using the IIS MANAGER > FEATURES > URL Rewrite > Add Rule > canonical domain name, but the problem is that then I can choose one address of those four, that will cause all the other three to be redirected to that, which is not what I need to do.

Can you please help and advise? Is URL Rewrite is a good and possible way to do this?

share|improve this question

migrated from stackoverflow.com Jul 29 '13 at 12:38

This question came from our site for professional and enthusiast programmers.

Any ideas, someone? – Eran Jul 27 '13 at 8:51

Here is the solution:

Add the following rules to the web config:

      <rule name="Redirect domain 1">
        <match url="(.*)" />
          <add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
        <action type="Rewrite" url="http://example.com/{R:1}" />
      <rule name="Redirect domain 2">
        <match url="(.*)" />
          <add input="{HTTP_HOST}" pattern="^example\.net$" />
        <action type="Redirect" url="http://www.example.net/{R:1}" />
share|improve this answer

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.