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.

My question is similar to Redirect subdomain to subdomain on new domain except I'm using IIS 7. The application is ASP.NET framework 2.0.

I have a url cust1.olddomain.com and I need to redirect to cust1.newdomain.com.

I need to maintain the subdomain but I need the domain to change so that the user never sees olddomain.com, and I have X number of cust subdomains.

I am able to route everything where it needs to go using DNS, but I can't figure out how to change the domain so that olddomain.com is never displayed. I was hoping to make this a 301 redirect, but from what I have read so far I don't think that's possible.

Thoughts?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Yea, I answered my own question!

For IIS 7 you can install the URL Rewrite Module from the MS Web Platform Installer or download it separately. Once installed, this essentially gives you the power of mod_rewrite in IIS.

To solve my redirect issue I created a new redirect entry as shown below. The URL Rewrite module provides a user interface for creating the redirect which then writes the entry to the site's web.config, like many other IIS modules.

<rewrite>           
        <rules>
            <rule name="RedirectToNewDomain" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="*.olddomain.com*" />
                </conditions>
                <action type="Redirect" url="http://{C:1}.newdomain.com{C:2}{PATH_INFO}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

What I am doing with this redirect is allowing all urls into the rule with the wildcard match url="*". Then I am conditionally pattern matching on the old domain. The asterisks in the conditional pattern match allow me to have back-references to whatever matches the pattern, which I then plug as {C:1} & {C:2} in the redirect action. It's the {C:1} back-reference that allows me to maintain my subdomain during the redirect and is the answer to the problem.

share|improve this answer
add comment

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.