【问题标题】:Syntax in IIS to use re-write subdomain as path of {HTTP_HOST}IIS 中使用重写子域作为 {HTTP_HOST} 路径的语法
【发布时间】:2022-01-05 11:17:17
【问题描述】:

假设我有一个站点:https://sub.domain.example,将其变为 https://domain.example/sub 的正确语法是什么

无论子域和顶级域(例如.com、.net、.org)如何,都需要重定向将用户推送到https://domain.example/sub 这是我尝试过但没有成功的方法--

<rules>
  <rule name="SubDomain to Subdirectory">
   <match url=".*" />
    <conditions>
     <add input="{HTTP_HOST}" pattern="^(\w+)\.(.*)$" />
    </conditions>
    <action type="Rewrite" url="https://domain.example/{C:1}" />
  </rule>
</rules>

【问题讨论】:

  • HTTP_HOST 不是域,它包括http:// 和端口。所以尝试使用 SERVER_NAME。

标签: redirect iis syntax url-rewriting


【解决方案1】:

您可以尝试以下规则来实现您的需求:

<rule name="test" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="on" />
                    <add input="{HTTP_HOST}" pattern="([_0-9a-z-]+)\.(.*)" />
                </conditions>
                <action type="Redirect" url="https://domain.example/{C:1}" />
            </rule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2016-04-03
    • 2010-10-07
    • 2020-09-30
    • 1970-01-01
    相关资源
    最近更新 更多