【问题标题】:Prepend www second level domain rewrite前置 www 二级域重写
【发布时间】:2015-03-12 21:22:42
【问题描述】:

我想将 www 添加到网站的每个域名中。 这些是我喜欢包含的域:

  • domain.com
  • domain.nl
  • domain.de
  • domain.co.in

到目前为止我所拥有的是:

<rule name="Prepend www to 2nd level domain names" enabled="true" stopProcessing="true">
           <match url=".*" />
           <conditions trackAllCaptures="true">
              <add input="{HTTP_HOST}" pattern="^([^.]+\.[^.]+)$" />
                  <add input="{CACHE_URL}" pattern="^(.+)://" />
           </conditions>
           <action type="Redirect" url="{C:2}://www.{C:1}/{R:0}" />
            </rule> 

这适用于所有域,除了 co.in。我不确定如何将 TLD 包含多个“.”?

【问题讨论】:

  • 我认为您可能希望将“正则表达式”标签添加到您的问题中。我相信该模式是正则表达式,可以在上面的部分中重写您的正则表达式的人可能会帮助您找到答案。

标签: asp.net regex iis rewrite


【解决方案1】:

你可以使用&lt;add input="{HTTP_HOST}" pattern="^domain.*" /&gt;

工作原理的更长版本在这里:Forwarding http://mydomain.com/ctrlr/act/val to http://WWW.mydomain.com/ctrlr/act/val

基本上和我上面写的一样。
这是适用于支持 TLD 的规则

<rule name="Add WWW prefix" >
  <match url="(.*)" ignoreCase="true" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^domain\.(.*)" />
  </conditions>
  <action type="Redirect" url="http://www.domain.{C:1}/{R:1}"
          redirectType="Permanent" />
</rule>

【讨论】:

  • 那行不通。如果添加 www.在前面它被重定向到 www.www.domain.com
  • 但模式是“以域开头”而不是“以 WWW 开头”
  • 是的,我不确定如何配置它。我也尝试过这种模式,但它也不起作用: ^[^\sw\.@/]([0-9a-zA-Z\-\.]*[0-9a-zA-Z\-]+ \.)(co.in|de|com|nl|CO.IN|DE|COM|NL)
  • 我在答案中添加了更多信息 - 这应该可以。
猜你喜欢
  • 2010-12-10
  • 2012-06-05
  • 2012-10-17
  • 2014-06-27
  • 2014-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多