12

I basically want to match the exact address

http://www.example.com/mysite

and redirect it to

http://www.example2.com/something/something

If possible I want to be able to do it with IIS because I have coded an internal rewriting module for example.com that rewrites user friendly URLS to aspx pages, and I don't want any interference with the other site.

NINJA EDIT:

I want to keep the address as http://www.example.com/mysite so I need to rewrite it not redirect it.

James Hay
  • 7,115
  • 6
  • 33
  • 57

1 Answers1

24

This should do the job:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect mysite" stopProcessing="true">
                    <match url="^mysite$" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.example2.com/something/something" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Marco Miltenburg
  • 6,123
  • 1
  • 29
  • 29
  • 1
    This works, but it doesn't keep the original address in the bar. Is this possible? – James Hay Nov 02 '11 at 20:20
  • 2
    In that case you will need to set up a reverse proxy by installing the [ARR module](http://www.iis.net/download/ApplicationRequestRouting) in IIS. Not sure though if this would be a great solution for this situation especially when example2.com is hosted elsewhere. – Marco Miltenburg Nov 02 '11 at 21:22
  • Ah probably not worth it. Thanks. – James Hay Nov 02 '11 at 21:24
  • 2
    Since I had same issue and thought someone might come here, this is the solution for your actual question: http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing – Barsham Sep 28 '16 at 07:17