排除测试子域被搜索引擎抓取(带SVN存储库)

时间:2011-07-18 20:18:24

标签: .htaccess mod-rewrite web-crawler robots.txt google-webmaster-tools

我有:

  • domain.com
  • testing.domain.com

我希望搜索引擎抓取domain.com并将其编入索引,但不要测试test.domain.com

测试域和主域共享相同的SVN存储库,因此我不确定单独的robots.txt文件是否可行...

2 个答案:

答案 0 :(得分:11)

1)创建单独的robots.txt文件(例如,将其命名为 robots_testing.txt )。

2)将此规则添加到网站根文件夹中的.htaccess:

RewriteCond %{HTTP_HOST} =testing.example.com
RewriteRule ^robots\.txt$ /robots_testing.txt [L]

它将重写(内部重定向)robots.txtrobots_testing.txt IF域名= testing.example.com的任何请求。

或者,反之亦然 - 为除robots.txt以外的所有域重写robots_disabled.txtexample.com的所有请求:

RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^robots\.txt$ /robots_disabled.txt [L]

答案 1 :(得分:2)

testing.domain.com应该拥有自己的robots.txt文件,如下所示

User-agent: *
Disallow: /

User-agent: Googlebot
Noindex: /

位于http://testing.domain.com/robots.txt
这将禁止所有机器人用户代理,并且谷歌会查看Noindex以及我们只是为了好的衡量标准。

您还可以将子域名添加到网站管理员工具中 - 按robots.txt屏蔽并提交网站删除(但这仅适用于Google)。有关更多信息,请查看 http://googlewebmastercentral.blogspot.com/2010/03/url-removal-explained-part-i-urls.html

相关问题