【问题标题】:IIS Rewrite - Add WWW but not to subdomainsIIS 重写 - 添加 WWW 但不添加到子域
【发布时间】:2016-04-28 03:08:08
【问题描述】:

我运行了一项在线服务,我最近在其中添加了一个 AWS 负载均衡器。

以前,一切都在没有 www 的域上运行,但由于 AWS ELB 可以更改其 IP,我们必须使用 CNAME 记录而不是 A 记录来运行设置。 CNAME 记录不能指向根域。所以我必须将所有内容都重写为 www。

我们有多个客户,其中大约 50% 使用自己的域,其余的作为我们主域的子域运行。

我需要的是:

example.com -> www.example.com  
www.example.com -> www.example.com  
customer1.ourdomain.com --> customer1.ourdomain.com  
customer2.ourdomain.com --> customer2.ourdomain.com

我在web.config中设置IIS重写规则不是最好的,但我希望有人能指出正确的解决方案。

以前我们一直在运行这个,用于删除 www,但现在我需要相反的。

    <rule name="Remove www" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
    </rule>

一切都在运行 http(目前)。

【问题讨论】:

    标签: mod-rewrite iis


    【解决方案1】:
        <rule name="Add www">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^ourdomain\.com" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}{UNENCODED_URL}" redirectType="Permanent" />
        </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-12
      • 2016-05-19
      • 2012-01-07
      • 2016-03-09
      • 2016-09-14
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      相关资源
      最近更新 更多