使用IIS 8将多个子域重定向到一个站点下的特定文件夹

时间:2014-02-26 17:36:38

标签: iis binding url-rewriting subdomain

所以基本上这就是我要做的事情。我们有一个域名“abc.com”,由不相关的公司托管在其他地方。我们有一个内部Web服务器,我们试图通过单个IIS站点下的子域托管多个网站。例如:

Server
 Sites
  Default Web Site (The direct IP would lead to here but that's it)
   > Site1 (site1.abc.com)
   > Site2 (site2.abc.com)
   > Site3 (site3.abc.com)

不幸的是,网站的结构是由安装应用程序的人以这种方式进行的,并且无法移动,因此添加和移动网站对我来说真的不是一个选择。我知道如何将默认站点绑定到IP地址并执行主机头但我不确定如何使该站点将这些子域转到正确的文件夹。我已经读过URL重写可能是选项,但我有点困惑,它不能是site1.abc.com/Site1这是我担心URL重写会做的。

任何帮助将不胜感激。感谢您的时间。 :)

1 个答案:

答案 0 :(得分:0)

您的Url重写规则必须匹配所有内容,然后在主机名上有条件,如下所示:

<rules>
     <rule name="site1" enabled="true" stopProcessing="true">
         <match url=".*" />
         <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
             <add input="{HTTP_HOST}" pattern="site1.abc.com" />
         </conditions>
         <action type="Rewrite" url="/site1/{R:0}" />
     </rule>
     <rule name="site2" enabled="true" stopProcessing="true">
         <match url=".*" />
         <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
             <add input="{HTTP_HOST}" pattern="site2.abc.com" />
         </conditions>
         <action type="Rewrite" url="/site2/{R:0}" />
     </rule>
</rules>

这些规则将从abc.com/site1获取site1.abc.com请求的内容,但用户仍会看到site1.abc.com