2015-04-23 62 views
0

是否可以从URL中删除一个子域名(或基本上像www一样)?从IIS或ASP.net MVC或haproxy的URL中删除子域名

实施例: subdomain.domain.com/specific/link/forsubdomain - >domain.com/specific/link/forsubdomain

并且不让它指向主域和返回404错误, 示例: domain.com/specific/link/forsubdomain - >返回404,因为它只存在于子域中。

如果可以在Haproxy中做某些事情或者在ASP.net MVC中伪装URL可以打开它的路由表修改。

不只是IIS配置。

只是想知道是否有可能改变我的网址,并仍然指向子域名网站。

回答

1

如果我正确理解你的问题,你是指规范的URL。

在IIS中,您可以使用URL Rewrite,这是一个您可以手动安装或通过Web平台安装程序(如果尚未安装)的模块。

这允许你创建一个url重写规则,你可以配置每个站点,沿着某些东西;

<rule name=”Redirect URL to WWW version” 
    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> 

您可以手动添加规则到网站的web.config文件或IIS网站管理员工具中使用的GUI。

有很多reference和许多教程可从微软和许多博客。

一个example of a complete web.config只是做这种类型的重定向。

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

如果URL是:tomatoes.contoso.com并且让它删除“tomato”并且是contoso.com,但仍然指向子域名,那么这样做也可以吗? – MightyMight

+0

你的意思是,如果有人键入tomato.contoso.com,你仍然希望它返回到www.tomatoes.contoso.com?如果是这样,您只需要使规则更加具体即可在条件和操作部分中包含子域。 –

+0

我的意思是如果有人键入** tomatoes.contoso.com **,它将被屏蔽,伪装或重写为** contoso.com **。但仍指向子域而不是主域。这可能吗? – MightyMight