其实robots.txt也不是百分之百的可以阻止蜘蛛爬行你的网站,我自己结合某些资料写了一小段代码,貌似可以彻底解决这个问题,不对的地方请大家多多指教:
if(preg_match("/(Googlebot|Msnbot|YodaoBot|Sosospider|baiduspider|google|baidu|yahoo|sogou|bing|coodir|soso|youdao|zhongsou|slurp|ia_archiver|scooter|spider|webcrawler|OutfoxBot)/i", $_SERVER['HTTP_USER_AGENT'])){
header('HTTP/1.1 403 Forbidden');
exit;
}
<?php
wp_head();
if(preg_match("/(Msnbot|YodaoBot|Sosospider|baiduspider|baidu|sogou|bing|coodir|soso|youdao|zhongsou|slurp|ia_archiver|scooter|spider|webcrawler|OutfoxBot)/i", $_SERVER['HTTP_USER_AGENT'])){
header('HTTP/1.1 403 Forbidden');
exit;
}
?>
<?php if(in_category('指定分类ID')) {?>代码<?php }?> 禁止蜘蛛爬行指定的分类