我有:


domain.com
testing.domain.com


我希望由搜索引擎对domain.com进行爬网和编制索引,但不希望testing.domain.com

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

最佳答案

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请求重新写入(内部重定向)到testing.example.com

或者,执行相反的操作-将除robots.txt以外的所有域的所有robots_disabled.txt请求重写为example.com

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

09-10 07:21
查看更多