Nginx方式:
打开Nginx的配置文件,在server节点下加入:
//如果User agent是百度、360、bing、google、sogou蜘蛛, 则301到新域名。
if ($http_user_agent ~ "Baiduspider|360Spider|bingbot|Googlebot|Sogou web spider" )
{
return 301 https://www.xxgeek.com$request_uri;
}
PHP方式:
<?php $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//取url路径 if(strpos($_SERVER['HTTP_REFERER'],'baidu.com')){ //判断是不是百度 header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location:https://www.xxgeek.com'.$request_uri); //重定向到新域名。 } ?>
JS方式:
<script type="text/javascript"> var s=document.referrer;//获取来路, 如果是搜索引擎,则跳转。 if(s.indexOf("baidu")>0 || s.indexOf("google")>0 || s.indexOf("so")>0 || s.indexOf("sogou")>0){ location.href="https://www.xxgeek.com"; } </script>
相关文章
暂无评论...