【问题标题】:How can I redirect sub-domain to primary domain?如何将子域重定向到主域?
【发布时间】:2015-06-11 19:53:48
【问题描述】:

我有一个场景,我有两个指向同一服务器的域,一个是所有子站点的主域,然后每个子站点都有辅助域,所以我想要做的是将辅助域重定向到使用 web.config 文件的主域。

例如:如果有人输入www.domain-secondary.com,它应该重定向到www.domain.com/subsite

更新:根据对这个问题的一些答案和一些修改,我设法使它工作,但显然它只有在域不包含任何特殊字符(如æ、ø、å)时才有效.我该如何解决这个问题?请帮忙

包含特殊字符的非工作代码

<rule name="Redirect to WWW rule 2" stopProcessing="true">
 <match url="(.*)" ignoreCase="true" />
 <conditions>
 <add input="{HTTP_HOST}" pattern="^www.skivebøligmøntering\.dk$" />
 </conditions>
 <action type="Redirect" url="http://www.skive.dk/skive-boligmontering/{R:1}" redirectType="Permanent" />
 </rule>  

【问题讨论】:

  • @TZHX 搞错了请忽略

标签: asp.net redirect iis dns web-config


【解决方案1】:

试试这个。

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

【讨论】:

  • 感谢您的解决方案,但仍然没有帮助它没有重定向到主域
  • 我必须更改一些参数才能使此代码正常工作,但仍然存在包含特殊字符的域的问题??任何建议
猜你喜欢
  • 2012-07-22
  • 2017-07-10
  • 2016-06-11
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
  • 2016-08-13
  • 1970-01-01
相关资源
最近更新 更多