簡體   English   中英

使用web.config將根域重寫為不同的路徑,然后將其重寫為子域

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

我認為這應該是一個非常容易的任務,但是我為此感到困惑。

我想做的事:

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?

如果您將規則更改為以下內容,則可以使用此功能:

<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