2012-01-20 111 views
1

我已經創建了一個新的子域用於所有靜態資產(static.example.com),方法是創建一個新的A記錄並將它指向具有新IP的同一服務器然後使用與主www.example.com站點相同的DocumentRoot創建虛擬主機。我們已將靜態資源的所有引用指向靜態子域,但是可以通過static.example.com或www.example.com訪問所有網站資源。防止Cookieless subdomain被搜索引擎索引的靜態資產

問題是Google已經開始在static.example.com子域中索引html文件。防止Google將此域上的文件編入索引的最佳方法是什麼?

回答

5

有幾種方法可以做到這一點。一個是使用robots.txt

在根目錄下創建一個static.example.com.robots.txt文件,並在其中放入以下內容(不能使用robots.txt,因爲它與其他域共享)。

這將禁止所有的蜘蛛含Googlebot會

User-agent: * 
Disallow:/

爲了確保這只是從static.example.com網站服務添加以下規則來你的.htaccess在您的網站的根文件夾。

RewriteEngine On 
RewriteBase/


#if request is on static.example.com 
RewriteCond %{HTTP_HOST} ^static\.example\.com$ [NC] 
#serve robots.txt from static.example.com.robots.txt 
RewriteRule ^(robots\.txt)$ %{HTTP_HOST}.$1 [L,NC] 
+0

美麗,謝謝!有了這個指令,我是否必須手動請求刪除索引的子域名頁面,或者Google會在下次嘗試抓取它們時刪除它們? – Michelle

+0

@Michell您需要對索引中已有的網頁採取進一步措施:請參閱http://support.google.com/webmasters/bin/answer.py?hl=zh_CN&answer=1663427 –