简体   繁体   English

使用web.config将根域重写为不同的路径,然后将其重写为子域

[英]Rewrite root domain to different path then subdomain with web.config

I think this should be a quite easy task, but I somehow struggle on it. 我认为这应该是一个非常容易的任务,但是我为此感到困惑。

What i want to do: 我想做的事:

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

My folder/file structure 我的文件夹/文件结构

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

Here my current ruleset: 这是我当前的规则集:

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

What currently happens is, that every call to mydomain.ch or demo.mydomain.ch is redirected to the angular app. 当前发生的情况是,每次对mydomain.ch或demo.mydomain.ch的调用都被重定向到angular应用程序。 What do I have to change to redirect the mydomain.ch to simplepage.html? 我必须更改些什么才能将mydomain.ch重定向到simplepage.html?

This would work if you change the rule to something like this: 如果您将规则更改为以下内容,则可以使用此功能:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM