阻止静态资产的无Cookie子域被搜索引擎索引

时间:2012-01-20 17:45:58

标签: .htaccess seo

我已经为所有静态资产(static.example.com)创建了一个新的子域,方法是创建一个新的A记录并将其指向具有新IP地址的同一服务器,然后创建一个具有相同DocumentRoot的虚拟主机。主要的www.example.com网站。我们已经将静态资源的所有引用都指向静态子域,但是可以通过static.example.com或www.example.com访问所有网站资源。

问题是Google已经开始在static.example.com子域上索引html文件。什么是阻止谷歌索引此域名文件的最佳方法?

1 个答案:

答案 0 :(得分: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]