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

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.

eg.
Old Domain: www.OldDomain.com
New Domain: www.NewDomain.com

User: www.OldDomain.com/user/PureKrome  -> 301 --> www.newDomain.com

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: Domain.com
CorrectDomain 1: www.Domain.com
CurrentDomain 2: AnotherDomain.com
CorrectDomain 2: www.AnotherDomain.com

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

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

Help!

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: tools.ietf.org/html/rfc2616#page-62 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

3 Answers 3

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
up vote 1 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 http://www.yoursitename.com and via http://yoursitename.com. Or, perhaps, you have recently changed you domain name from oldsitename.com to newsitename.com 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="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^ruslany\.net$" />
    </conditions>
    <action type="Redirect" url="http://ruslany.net/{R:1}" 
            redirectType="Permanent" />
</rule>

To see an example of how that works try browsing to http://www.ruslany.net/2008/10/aspnet-postbacks-and-url-rewriting/. You will see in the browser’s address bar that “www” is removed from the domain name.

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

 
discard

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.