IIS Url Rewrite to another server

4.9k views Asked by At

I have an old url www.mydomain.com/customer/1. I changed that server to ww2 and it displays fine at ww2.mydomain.com/customer/1. On my new IIS 8.5 www server how can I put in a rewrite rule so if the user goes to www.mydomain.com/customer/1 they will redirect to ww2.mydomain.com/customer/1. I have tried numerous patterns in the Url Rewrite 2.0 module and nothing seems to work. All other www requests I do not want redirected, those stay on my new www server.

1

There are 1 answers

0
dana On

I you want to redirect a single path, /customer/1, then you should add this to Web.config on the www.mydomain.com server:

<rewrite>
    <rules>
        <rule name="Redirect 'www.mydomain.com/customer/1' to 'ww2.mydomain.com/customer/1'" stopProcessing="true">
            <match url="^customer/1$" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mydomain\.com$" />
            </conditions>
            <action type="Redirect" url="http://ww2.mydomain.com{REQUEST_URI}" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

If you wish to include additional paths, you can fiddle with the RegEx specified in the <match url="^customer/1$" /> tag.