代码之家  ›  专栏  ›  技术社区  ›  Stefan

将根域重写为其他路径,然后使用web将子域重写为其他路径。配置

  •  0
  • Stefan  · 技术社区  · 7 年前

    我认为这应该是一项相当容易的任务,但我不知何故努力了。

    我想做什么:

    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或演示。mydomain。ch被重定向到角度应用程序。重定向mydomain需要更改什么。ch至simplepage。html?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Aaron Chen    7 年前

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

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