Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

For one of our projects, we're doing a rebranding of the website name, logo, etc...

As such, we need to 301 Moved Permenantly redirect all users from the old domain to the new domain. With IIS7, that's pretty simple. We just create a new website that redirects all traffic to a host-headered domain .. to the new one.

But this loses their original destination resource.

Old Domain:
New Domain:

User:  -> 301 -->

Notice how it's going to the new domain BUT not to /user/PureKrome?

How can I do this so it goes to the new domain and keeps the original resource request? I'm guessing URL-ReWriter for IIS7 might help?

Also, what happens if I want to do this...

CurrentDomain 1:
CorrectDomain 1:
CurrentDomain 2:
CorrectDomain 2:

Is it also possible to have those in the same IIS website? So any URL to will 301 to

Right now I'm making 2 IIS websites, with a 301 hardcoded (which still means I lose the original resource request, too).


share|improve this question
If your resources are moving to a permanent new URI you should use a 301, not a 302. See this bit of the HTTP RFC: Sadly I can't tell you how to do this in IIS, though! – markdrayton Oct 19 '09 at 12:10
Updated to 301'.s – Pure.Krome Oct 24 '09 at 0:08
up vote 2 down vote accepted

RuslanY's Blog has a great post that describes how to do this with the IIS rewriter.

I will quote his Tip #3 :-

Very often you may have one IIS web site that uses several different host names. The most common example is when a site can be accessed via and via Or, perhaps, you have recently changed you domain name from to and you want your visitors to use new domain name when bookmarking links to your site. A very simple redirect rule will take care of that: view plaincopy to clipboardprint?

<rule name="Canonical Host Name" stopProcessing="true">
    <match url="(.*)" />
        <add input="{HTTP_HOST}" negate="true" pattern="^ruslany\.net$" />
    <action type="Redirect" url="{R:1}" 
            redirectType="Permanent" />

To see an example of how that works try browsing to You will see in the browser’s address bar that “www” is removed from the domain name.

share|improve this answer

This is a URL rewriting problem.
If you're on Apache you can put rules in the .htaccess file. IIS users have to purchase and install (although there's an evaluation version that lets you run one site per instance of IIS) the ISAPIRewrite ISAPI module, which interprets the .htaccess files.

share|improve this answer

Actually you need an http module for this. You can read the URL in the http module and keep the path, only change the hostname if it's different from your new domain name or doesn't start with www.

Let me know if you want more details or the code to do this.

share|improve this answer
So urlwriter can't do this? isn't that an Http Module? – Pure.Krome Oct 24 '09 at 4:36
I didn't really use urlwriter before so I'm afraid I can't help you with this. – Mee Oct 24 '09 at 6:52

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.