2016-04-24 17 views
0

我們在sitecore項目中實施了多站點解決方案。我們已將robots.txt置於網站根目錄下,以防止對生產服務器上的特定目錄進行爬網。如何避免搜索引擎在Sitecore多站點環境中特別在網站上爬行

現在我們打算在生產服務器上另外安裝一個網站beta.example.com,但我們希望避免對此子網域進行爬網。

我們該如何實現,因爲它是多站點環境,並且只有一個robots.txt文件。我們如何才能使此抓取機制適用於特定的網站。

我們是否需要爲此編寫任何管道機制。

感謝

回答

3

您可以添加自定義的處理程序,將如下處理您的robots.txt:

<customHandlers> 
    <handler trigger="robots.txt" handler="RobotsTxtHandler.ashx" /> 
</customHandlers> 

然後在你ashx背後的代碼,你可以編寫所需的邏輯加載你需要的robots.txt。

public void ProcessRequest(HttpContext context) 
{ 
    var database = Factory.GetDatabase("web"); 
    var path = string.Format("{0}{1}", Context.Site.RootPath, Context.Site.StartItem) 
    Item siteRoot = database.GetItem(path) 
    if (siteRoot != null) 
    { 
     context.Response.Clear(); 
     context.Response.ContentType = "text/plain"; 
     context.Response.ContentEncoding = System.Text.Encoding.UTF8; 

     //Write your code to fetch the robots.txt from sitecore item 
    } 

    context.Response.End(); 
} 

注意,ASHX的代碼隱藏應該繼承的IHttpHandler

你也需要添加處理程序在web.config中<system.webServer> <handlers>標籤下。

<add verb="*" path="RobotsTxtHandler.ashx" type="YourNamespace.RobotsTxtHandler, YourAssembly" name="RobotsTxtHandler" /> 

我的建議是,最好將你存儲一個robots.txt在Sitecore的項目每個站點,而不是網站的根目錄。這將使每個網站都有自己的robots.txt