web.config oldsite to newsite 301, domain/root to new page AND old pages to oldpages

16 Views Asked by At

In my web.config file I want to be able to accomplish both redirects below:

Redirect the root/domain: oldsite.org to newsite.org/this-is-thenewsite

AND page wildcard redirects: oldsite.org/any-all-oldpage to newsite.org/any-all-oldpage

What would be the proper way to accomplish both?

I currently redirect all old traffic to the new page And I know I can use {R0} or {R1} to wildcard the pages.

I just dont know the best way to do both TIA!

2

There are 2 best solutions below

0
ThomasArdal On

You can redirect one domain to another with a rule similar to this:

<rule name="Redirect" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^oldsite.org$" />
  </conditions>
  <action type="Redirect" url="https://newsite.org/{R:0}" redirectType="Permanent" />
</rule>

Source: Web.config redirects with rewrite rules - https, www, and more

0
ScottD On

Apparently using the following two match statements get me what I need.:

<match url=".+" negate="true" ignoreCase="true" />

looks for just the domain in the URI

<match url="^(.*)$" ignoreCase="false" />

looks at any files in the URI