我认为这应该是一项非常容易的任务,但我在某种程度上仍在努力。
我想做什么:
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 app。我需要更改哪些内容才能将mydomain.ch重定向到simplepage.html?
答案 0 :(得分: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>