【问题标题】:Rewrite root domain to different path then subdomain with web.config将根域重写为不同的路径,然后使用 web.config 重写子域
【发布时间】:2018-01-23 22:03:05
【问题描述】:

我认为这应该是一项相当容易的任务,但我不知何故为此而苦苦挣扎。

我想做什么:

mydomain.ch -> should redirect to a simple html page in folder public
demo.mydomain.ch -> should redirect to a angular application
demo.mydomain.ch/api -> is the backend (express.js) for the angular application

我的文件夹/文件结构

web.config
demo
-> simplepage.html
-> index.html
-> angular.js
-> ...
backend
-> server.js

这是我当前的规则集:

<rule name="mydomain.ch rule"  stopProcessing="true">
    <match url="^mydomain\.ch$" />
    <action type="Rewrite" url="demo/simplepage.html"/>
</rule>

<rule name="Root rule">
    <match url="^$" />
    <action type="Rewrite" url="demo/index.html"/>
</rule>

<!-- For static files, redirect to the URI -->
<rule name="Static files">
    <action type="Rewrite" url="demo{REQUEST_URI}"/>
</rule>

<!-- For Express.js middleware API, if using api/ prefix, then use server.js -->
<rule name="Express.js URIs">
    <match url="api/*"/>
    <action type="Rewrite" url="backend/server.js"/>
</rule>

<!-- For Angular.js URIs, rewrite to the index.html file -->
<rule name="Angular">
    <match url=".*"/>
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    </conditions>
    <action type="Rewrite" url="demo/index.html"/>
</rule>

目前发生的情况是,对 mydomain.ch 或 demo.mydomain.ch 的每次调用都被重定向到 Angular 应用程序。要将 mydomain.ch 重定向到 simplepage.html,我需要进行哪些更改?

【问题讨论】:

    标签: azure iis web-config azure-web-app-service


    【解决方案1】:

    如果您将规则更改为以下内容,这将起作用:

    <rule name="mydomain.ch rule"  stopProcessing="true">
        <match url="^$" /> 
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^mydomain\.ch$" />
        </conditions>
        <action type="Rewrite" url="demo/simplepage.html"/>
    </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多