指向一台服务器的多个域。使用重写规则设置首选域

时间:2015-11-09 22:42:43

标签: c# web-config iis-8

我刚为客户推出了一个新网站。作为新发布的一部分,我想尝试整理他们的域名。目前他们有3个域名都指向相同的服务器,这在SEO方面是不好的。不幸的是,我无法直接访问服务器的IIS配置,因为它与托管服务提供商一样,但我想确保如果用户进入其中两个域,则会将其重定向到我们认为的主域。

到目前为止,我有以下设置:

<rewrite>
    <rules>
    <rule name="Redirect to WWW" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^maindomain.dk$" />
        <add input="{HTTP_HOST}" pattern="^otherdomain1.dk$"  />
        <add input="{HTTP_HOST}" pattern="^otherdomain2.dk$"  />
    </conditions>
    <action type="Redirect" url="http://www.maindomain.dk/{R:0}"
        redirectType="Permanent"/>
    </rule>
     </rules>
    </rewrite>

我只想让Google注册我的maindomain.dk。虽然我在这里,但我只是希望它使用这个域的www.maindomain.dk版本。但是,上面的脚本不起作用。

当我导航到otherdomain1.dk时,它只是转到该URL。如果我导航到otherdomain2.dk,它会转到该URL。 maindomain.dk表现出正确的行为。我需要做些什么才能让它发挥作用?

1 个答案:

答案 0 :(得分:1)

你应该定义条件&#39;逻辑分组是&#34;匹配任何&#34;

<conditions logicalGrouping="MatchAny">

此外,你应该修复你的模式以逃避点

<add input="{HTTP_HOST}" pattern="^maindomain\.dk$" />
<add input="{HTTP_HOST}" pattern="^otherdomain1\.dk$"  />
<add input="{HTTP_HOST}" pattern="^otherdomain2\.dk$"  />