0

We have a server with multiple individual websites:

domain.com/masterSite    
domain.com/site1    
domain.com/site2    
domain.com/siteN

We're in the process of migrating the multiple individual websites to a multi-tenant application (/mastersite). We are not doing this all at once; rather, we're migrating individual sites (200+) one at a time. And when a site is migrated to the multi-tenant site, we need a forwarding rule.

Example:

domain.com/site1 --> domain.com/masterSite/site1
domain.com/siteN --> domain.com/masterSite/siteN

The site names are all random, so we're going to use a Rewrite Map.

The issue is that I'm having trouble figuring out the pattern matching when using a rewrite map so that all requests to the path are forwarded regardless of extra URL data.

Here is current state:

<rewrite>
      <rewriteMaps>
        <rewriteMap name="ForwardToMTDB" defaultValue="">
          <add key="/site1" value="/masterSite/site1" />
          <add key="/site2" value="/masterSite/site2" />
        </rewriteMap>
      </rewriteMaps>
      <rules>
        <rule name="Rewrite Rule" enabled="true" stopProcessing="true">
          <match url="(.+)" />
          <conditions>
            <add input="{ForwardToMTDB:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" logRewrittenUrl="true" redirectType="Found" />
        </rule>
      </rules>
    </rewrite>

Examples of requests that should ALL go to domain.com/masterSite/siteN

domain.com/SiteN
domain.com/siteN/ 
domain.com/siteN/foo/bar
domain.com/siteN/somePage.aspx
domain.com/siteN/blah1/blah2/blah3/blah4/etc
Jeffrey
  • 143
  • 2
  • 10

1 Answers1

0

So, I got it to work. Here is the rule:

 <rule name="Redirect Rule" enabled="true" stopProcessing="true">
      <match url="^(.+?)([/?$])" />
      <conditions logicalGrouping="MatchAny">
        <add input="{ForwardToMTDB:{R:1}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Found" />
    </rule>

I also had to modify the key value in the rewrite map to exclude leading slash:

<rewriteMap name="ForwardToMTDB" defaultValue="">
  <add key="site1" value="/masterSite/site1" />
  <add key="site2" value="/masterSite/site2" />
</rewriteMap>

I read many posts related to what I was trying. For instance, this post talked about matching an optional trailing slash. I built on that using the Test Pattern tool in IIS continually until I got the back reference to always be what I needed regardless of additional data in URL.

Jeffrey
  • 143
  • 2
  • 10