2015-04-23 63 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