wingyip
wingyip

Reputation: 3536

IIS Rewrite Rule - Redirect from one domain binding to another domain binding

I have multiple bindings on my IIS site and I want to catch all requests to

any of the following - domainA.co.uk, www.domainA.co.uk, domainA.com, www.domainA.com

and redirect to a page on one of the other bindings on the site

www.domainB.com/my-folder/

Is this possible with URL Rewrite?

Upvotes: 1

Views: 4817

Answers (2)

Victor Leontyev
Victor Leontyev

Reputation: 8736

It is possible with url rewrite, you need to use this rule:

<rule name="all domains to www.domainB.com/my-folder" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^domainA.co.uk$" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^www.domainA.co.uk$" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^domainA.com$" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^www.domainA.com$" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="http://www.domainB.com/my-folder/{R:1}" />
</rule>

It will redirect urls:

  • domainA.co.uk to www.domainB.com/my-folder/
  • www.domainA.co.uk to www.domainB.com/my-folder/
  • domainA.com to www.domainB.com/my-folder/
  • www.domainA.com to www.domainB.com/my-folder/
  • www.domainA.com/something to www.domainB.com/my-folder/something (in case if you dont want that, just remove {R:1} form rule)

Upvotes: 5

Joseph M Tsai
Joseph M Tsai

Reputation: 568

it is possible you could use the rewrite to redirect the domain

<rewrite>
      <rules>
        <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">

            <add input="{HTTP_HOST}" negate="true" pattern="^www.(.*)$" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://www.{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>     

Upvotes: -1

Related Questions