软文营销
当前位置: 四五合围 > 网络营销知识 > 软文营销
Worepress 禁止PC首页访问 不影响蜘蛛抓取的方法
发布日期:2024-01-26 阅读次数:

                                                                                                                       

作者:导航鸭 

                                                                     

一、wordpress 禁止PC首页访问 不影响蜘蛛抓取的方法
  • function block_homepage_for_pc() {
  •     if ( ! is_admin() && ! is_feed() ) {
  •         $user_agent = $_SERVER['HTTP_USER_AGENT'];
  •         if ( strpos( $user_agent, 'Googlebot' ) === false && strpos( $user_agent, 'Bingbot' ) === false && strpos( $user_agent, 'Slurp' ) === false && strpos( $user_agent, 'DuckDuckBot' ) === false ) {
  •             global $wp_query;
  •             $wp_query->set_404();
  •             status_header( 404 );
  •             get_template_part( 404 );
  •             exit();
  •         }
  •     }
  • }
  • add_action( 'template_redirect', 'block_homepage_for_pc' );
二、nginx 屏蔽网站首页访问 允许蜘蛛访问的方法
  • location = / {
  •     if ($http_user_agent !~* (spider|bot|googlebot|bingbot|yandex|msnbot|slurp)) {
  •         return 403;
  •     }
  •     # other rules
  • }
三、NGINX 禁止PC访问 不影响蜘蛛抓取的方法
  • if ($http_user_agent !~* (android|iphone|ipod|ipad|windows\s*phone|blackberry|symbian|bot|crawl|spider)) {
  •     return 403; # 拒绝所有 PC 访问请求
  •     }
四、只禁止访问首页
  • set $PCindex 银行卡/path/to/pc/index.html银行卡;

  • location = / {
  •     if ($http_user_agent !~* 银行卡bot|crawler|spider银行卡) {
  •         return 403;
  •     }
  •     try_files $PCindex =404;
  • }
国内搜索引擎蜘蛛:Baidu: Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
360: Mozilla/5.0 (compatible; 360Spider/1.0; +http://www.360.cn/spider.html)
Sogou: Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)
Shenma: Mozilla/5.0 (compatible; ShenmaBot/1.0; http://www.shenma.com)
Yisou: Mozilla/5.0 (compatible; YisouSpider; +http://www.yisou.com/help/webmaster/spider.html)
Easou: EasouSpider; +http://www.easou.com/search/spider.html
国外搜索引擎蜘蛛:
Google: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Bing: Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
Yahoo: Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
Yandex: Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)
Baidu: Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
DuckDuckBot: DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)
需要注意的是,蜘蛛的 User-Agent 可能会随着搜索引擎的升级和更新而变化,因此这里列举的 User-Agent 只是一些常见的,不一定是比较新的。


声明:我公司全力支持关于《中华人民共和国广告法》实施的“比较限化违禁词”相关规定,且已竭力规避使用相关“违禁词”(如比较、顶……)等比较限化词汇,如果还有“比较限化违禁词”用在我公司网站内,我公司声明其全部失效。本声明在我公司网站的所有页面内均有效,所有访问我公司网站的人员、客户均表示默认此内容,不支持任何以“比较限用语、比较限词、广告违禁词”等为借口或理由来投诉我公司违反《中华人民共和国广告法》或《新广告法》等相关法律,以及以此来索要赔偿等的行为。我中心已竭力对旗下所有网站及其内容进行了有*的排查与清理,如仍残留有比较限用语,本公司申明其全部失效,请直接默认其无效,并请及时联系我中心进行更改,感谢您的配合与支持,谢谢!
本站访客:3657