A-A+

Robots.txt的优化

2010年06月27日 经验技巧 暂无评论 阅读 67 次浏览 次
    •       Robots.txt文件对于Wordpress自建博客在搜索引擎中获取较好的排名和流量有很大的作用,因为它可以有效防止 wordpress复制内容的不好影响。Google在其官方指南中就谈到Robots.txt对于google爬虫的作用:

      Make use of the robots.txt file on your web server. This file tells crawlers which directories can or cannot be crawled. Make sure it’s current for your site so that you don’t accidentally block the Googlebot crawler.

      那么该如何设置robots.txt文件呢?对于wordpress博客,我们可以从两个地方来设置好对于搜索引擎爬虫的限制访问。

      一、header.php中的robots meta的优化

      1. <?php if(is_single() || is_page() || is_home()) { ?>
      2.     <meta name="googlebot" content="index,follow" />
      3.     <meta name="robots" content="all,index,follow" />
      4.   <meta name="msnbot" content="all,index,follow" />
      5. <?php } else { ?>
      6.     <meta name="googlebot" content="noindex,noarchive,follow" />
      7.     <meta name="robots" content="noindex,follow" />
      8.   <meta name="msnbot" content="noindex,follow" />
      9. <?php }?>

      这样的代码告诉搜索引擎爬虫除了首页、文章页面以及独立页面外的其他页面只检索不收录。
      二、robots.txt的设置
      在网站的根目录下添加robots.txt并正确设置是很有用处的。以下的例子简单告诉robots.txt该怎么使用。

    • 禁止爬虫访问以下目录:
      1. Disallow: /about/
      2. Disallow: /contact/
      3. Disallow: /tag/
      4. Disallow: /wp-admin/
      5. Disallow: /wp-includes/
      6. Disallow: /contact
      7. Disallow: /wp-
      8. Disallow: /feed/
      9. Disallow: /trackback/
    • 禁止google爬虫访问以下文件名的文件:
      1. User-agent: Googlebot
      2. Disallow: /*.php$
      3. Disallow: /*.js$
      4. Disallow: /*.inc$
    • 禁止爬虫访问地址中带?的地址:
      1. Disallow: /*?*
标签:

给我留言