我們在采用WordPress程序建站的時候,默認(rèn)WP會有給我們根目錄創(chuàng)建一個 robots.txt 文件。我們應(yīng)該有知道,robots.txt 文件的作用是可以控制抓取協(xié)議,比如我們希望哪些目錄不被搜索引擎抓取,設(shè)置允許抓取的,一般的我們robots.txt單站點(diǎn)的協(xié)議是如何寫的呢?
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/ Sitemap: http://bjj.org.cn/wp-sitemap.xml
我們應(yīng)該知道,WordPress還可以建議多站點(diǎn),如果是WordPress多站點(diǎn) robots.txt 如何寫呢?多站點(diǎn)需要用到robots_txt鉤子來完成。
function robots_mod( $output, $public ) { $output .= "Disallow: /feed\n"; $output .= "Disallow: /trackback\n"; $output .= "Disallow: /user/"; return $output; } add_filter( 'robots_txt', 'robots_mod', 10, 2 );
這樣我們就可以在默認(rèn)的基礎(chǔ)上添加自定的幾個目錄限制抓取。放到對應(yīng)站點(diǎn)主題Functions.php中。
評論