【问题标题】:How can I redirect some (but not all) http requests on one IIS host to https on another IIS host?如何将一台 IIS 主机上的一些(但不是全部)http 请求重定向到另一台 IIS 主机上的 https?
【发布时间】:2015-07-18 12:29:37
【问题描述】:

我们有以下要求:

  • 重定向 http://host1.domain.com/resource1/* 到 https ://host2.domain.com/resource1/*(保留所有内容,包括 /resource1/* 和查询字符串等)

  • 根本不重定向 http://host1.domain.com/resource2/*

  • 我们不能使用应用程序请求路由

  • IIS 7.5

我们可以使用重定向或重写,无论哪个有效。似乎使用“反向代理”选项设置入站重写规则(使用带有 {CACHE_URL} 的输入创建条件)接近了,但我无法让它与“匹配 URL”部分中的模式一起使用/资源1/*。重定向似乎只允许将资源重定向到同一主机上的另一个资源,而不是不同主机上的。

我们怎样才能做到这一点?

【问题讨论】:

    标签: iis rewrite


    【解决方案1】:

    您可以为此使用 URL 重写。只需在应用程序的 web.config 中添加如下所示的内容,其中添加条件以仅匹配主机名 (host1.domain.com) 并使用正则表达式匹配 resource1 并将其传递给操作:

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Redirect resource1" stopProcessing="true">
              <match url="resource1/.*" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="^host1.domain.com$" />
              </conditions>
              <action type="Redirect" url="https://host2.domain.com/{R:0}" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 2019-07-31
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多