I believe many webmasters have encountered this situation: the search function in the website is used by bad elements , by continuously searching for sensitive keywords in the search box on the site, a large number of spam search result pages with sensitive keywords on TITLE are generated (as shown below). Since Baiduspider has a limited crawl quota for each site, these spam search result pages will be included by Baidu, which will cause other meaningful pages not to be included due to quota issues. At the same time, Baidu's processing of spam pages may affect the normal performance of the website. Ranking.
For specific reference, please refer to Baidu’s official page http://zhanzhang.baidu.com/college/articleinfo?id=117
I will give you a method and my idea
The idea is like this. Those big guys who want to do this mostly still have to leave their QQ or phone number
Then I will match the rules inside, find out the numbers in the search, and then judge the length of the number string, and then judge whether it is a junk search
Provide the code:
<?php //@功能 屏蔽掉黑帽SEO的搜索关键字 //@By 阳兄 function findNum($str=''){ //取出字符串里面的所有数字 $str=trim($str); if(empty($str)){return '';} $result=''; for($i=0;$i<strlen($str);$i++){ if(is_numeric($str[$i])){ $result.=$str[$i]; } } return $result; } $the_lnum=strlen(findNum($q));//获取数字字符串长度 if($the_lnum>6){ //判断长度是否超过6 超过则直接301到搜索页面 header("HTTP/1.1 301 Moved Permanently"); header("Location: http://".$_SERVER['HTTP_HOST']."/search.php"); exit(); } ?>
The above is the entire content of this article, I hope you all like it.