简体   繁体   English

如何将子域重定向到主域?

[英]How can I redirect sub-domain to primary domain?

I have a scenario where I have two domains pointing to same server one is the primary domain to all sub-sites and then there is secondary domain for each sub-site so what I am trying to do is redirecting the secondary domain to primary domain using web.config file. 我有一个场景,我有两个指向同一台服务器的域,一个是所有子站点的主域,然后每个子站点都有一个辅助域,所以我想做的是使用以下命令将辅助域重定向到主域web.config文件。

For Example: if some one enters www.domain-secondary.com it should redirect to www.domain.com/subsite 例如:如果有人进入www.domain-secondary.com ,则应重定向到www.domain.com/subsite

update: As per some answers on this question and with some amendments i managed to made it work but apparently it only works if domain doesn't contains any special characters such as æ,ø,å. 更新:根据这个问题的一些答案和一些修改,我设法使其起作用,但显然只有在domain不包含诸如æ,ø,å之类的任何特殊字符时,它才起作用。 how can i resolve this issue? 我该如何解决这个问题? Please help 请帮忙

Non-working code which contains special characters 包含特殊字符的无效代码

<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>  

Try this one . 试试这个。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM