【问题标题】:Could you please advise how to resolve the issue with URL rewrite rules for azure web app?您能否建议如何解决 azure web 应用程序的 URL 重写规则问题?
【发布时间】:2021-02-24 18:38:34
【问题描述】:

我在 Azure Web App 上部署了一个 MVC 点网应用程序(多租户平台)。 我已经配置了两个租户:tenant1 和 tenant2,它们的 URL:

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

它们都可以通过 IE、Safari 等访问。我在 GoDaddy 上购买了两个域:

  1. domain1.com
  2. domain2.com

我想为他们配置 rewrite 规则,所以每当有人在他的浏览器中输入www.domain1.com 或 domain1.com 时,primer-test.azurewebsites.net/tenant1 的内容应该被提出。同样,对于 domain2。

我已将这两个自定义域附加到我的网络应用程序中,没有问题。我写了重写规则,但它们似乎没有按预期工作。

<?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>

知道可能出了什么问题吗?

非常感谢!

【问题讨论】:

  • 我的回答应该对你很有帮助。如果您需要帮助,请告诉我。

标签: azure url-rewriting web-config azure-web-app-service


【解决方案1】:

在这种情况下,从您提供的 URL 中,我可以看到 primer-test.azurewebsites.net 是您创建和使用的 webapp。 tenant1 和 tenant2 在 webapp 中应该是 virtual applications。

概念: Virtual application

相关帖子:

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

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

正确使用流程和测试步骤:

第 1 步。

准备工作,创建一个.net框架的主应用(在项目中使用web.config,目的是配置rewrite。

在门户中配置。

在站点路径下创建文件夹并通过zip部署虚拟应用程序。

在不重写设置的情况下对其进行测试。

第二步,修改RewriteTest项目中的web.config文件。

第 3 步。创建自定义域进行测试。

步骤 4. 测试结果。满足您的需求。

【讨论】:

    猜你喜欢
    • 2020-01-30
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 2023-03-06
    • 1970-01-01
    • 2017-01-28
    相关资源
    最近更新 更多