Search code examples
azureurl-rewritingweb-configazure-web-app-service

Could you please advise how to resolve the issue with URL rewrite rules for azure web app?


I have an MVC dot net application (multi-tenant platform) deployed on Azure Web App. I have configured two tenants: tenant1 and tenant2, with their URLs:

  1. primer-test.azurewebsites.net/tenant1 and
  2. primer-test.azurewebsites.net/tenant2

Both of them are accessible from IE, Safari etc. I purchased two domains on GoDaddy:

  1. domain1.com
  2. domain2.com

and I would like to configure the rewrite rules for them so whenever someone types in his browser either www.domain1.com or domain1.com, the content of primer-test.azurewebsites.net/tenant1 should be presented. Similarly, for the domain2.

I have attached these two custom domains to my web app, with no problem. I wrote the rewrite rules, but they seem to don't work as expected.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
    <rewrite>
      <rules>
        <rule name="domain1.com" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www.)?domain1.com" />
            <add input="{PATH_INFO}" pattern="^/tenant1/" negate="true" />
          </conditions>
          <action type="Rewrite" url="\tenant1\{R:0}" />
        </rule>
        <rule name="domain2.com" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www.)?domain2.com" />
            <add input="{PATH_INFO}" pattern="^/tenant2/" negate="true" />
          </conditions>
          <action type="Rewrite" url="\tenant2\{R:0}" />
        </rule>
      </rules>
    </rewrite>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\kobsq.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
    </system.webServer>
  </location>
</configuration>

Any idea what might be wrong?

Thanks very much!


Solution

  • In this case, from the URL you provided, I can see that primer-test.azurewebsites.net is the webapp you created and used. tenant1 and tenant2 should be virtual applications in webapp.

    Concept: Virtual application

    Related Posts:

    1. How to deploy a Flask+React application to Azure Web Service

    2. Hosting Two Website Under one Web App - Azure Services

    Correct use process and test steps:

    Step 1.

    Preparation work, create a main application of the .net framework (use web.config in the project for the purpose of configuring rewrite.

    enter image description here

    Configure in portal.

    enter image description here

    Create folder under site path and deploy virtual app by zip.

    enter image description here

    enter image description here

    enter image description here

    Test it without rewrite settings.

    enter image description here

    Step 2. Modify web.config file in RewriteTest project.

    enter image description here

    Step 3. Create custom domain to test.

    enter image description here

    Step 4. Test result. Fulfill your needs.

    enter image description here