说明:我们有时候页面有些内容由于某些因素,都要防止被搜索引擎收录,而禁止搜索引擎收录比较简单的办法是在Robots.txt
里设置规则,Robots
协议(也称为爬虫协议、机器人协议等)的全称是“网络爬虫排除标准”(Robots Exclusion Protocol
),网站通过Robots
协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓取。这里说下方法。
这里以WordPress
博客网站为例,在网站根目录Robots.txt
里添加如下规则:
User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/
Disallow: /wp-includes/
Disallow: /*/comment-page-*
Disallow: /*?replytocom=*
Disallow: /category/*/page/
Disallow: /tag/*/page/
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /comments/feed
Disallow: /?s=*
Disallow: /*/?s=*
Disallow: /attachment/
下面分别解释一下各项的作用:
1、Disallow: /wp-admin/、Disallow: /wp-content/和Disallow: /wp-includes/
用于告诉搜索引擎不要抓取后台程序文件页面。
2、Disallow: /*/comment-page-*和Disallow: /*?replytocom=*
禁止搜索引擎抓取评论分页等相关链接。
3、Disallow: /category/*/page/和Disallow: /tag/*/page/
禁止搜索引擎抓取收录分类和标签的分页。
4、Disallow: /*/trackback
禁止搜索引擎抓取收录trackback等垃圾信息
5、Disallow: /feed、Disallow: /*/feed和Disallow: /comments/feed
禁止搜索引擎抓取收录feed链接,feed只用于订阅本站,与搜索引擎无关。
6、Disallow: /?s=*和Disallow: /*/?s=*
禁止搜索引擎抓取站内搜索结果
7、Disallow: /attachment/
禁止搜索引擎抓取附件页面,比如毫无意义的图片附件页面。
上面只是些基本的写法,当然还有很多,不过够用了。当然像Typecho
、Emlog
,Zblog
这些博客就自己看着办,方法一样。
<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<ins class=”adsbygoogle”
style=”display:block; text-align:center;”
data-ad-layout=”in-article”
data-ad-format=”fluid”
data-ad-client=”ca-pub-2228624058246446″
data-ad-slot=”3312055326″></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<ins class=”adsbygoogle”
style=”display:block; text-align:center;”
data-ad-layout=”in-article”
data-ad-format=”fluid”
data-ad-client=”ca-pub-2228624058246446″
data-ad-slot=”3312055326″></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>