您可以重写robots.txt
到其他文件(让我们将此命名为“robots_no.txt”,其中包含:
User-Agent: *
Disallow: /
(来源:http ://www.robotstxt.org/robotstxt.html )
.htaccess 文件如下所示:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^robots.txt$ robots_no.txt
为每个(子)域使用自定义 robots.txt:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^sub.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.org$ [OR]
RewriteCond %{HTTP_HOST} ^example.org$
# Rewrites the above (sub)domains <domain> to robots_<domain>.txt
# example.org -> robots_example.org.txt
RewriteRule ^robots.txt$ robots_${HTTP_HOST}.txt [L]
# in all other cases, use default 'robots.txt'
RewriteRule ^robots.txt$ - [L]
除了要求搜索引擎阻止除 之外的所有页面之外www.example.com
,您也可以使用<link rel="canonical">
。
如果http://example.com/page.html
和http://example.org/~example/page.html
都指向http://www.example.com/page.html
,则将下一个标记放入<head>
:
<link rel="canonical" href="http://www.example.com/page.html">
另见谷歌关于 rel="canonical" 的文章