在PHP中,你可以使用301重定向来转移权重和蜘蛛。301重定向是一种永久重定向,用于将一个网页的URL重定向到另一个网页。

当使用301重定向时,搜索引擎会识别并理解重定向,并将原始页面的权重和蜘蛛转移到目标页面。这有助于确保在更改网站结构或重新定向URL时,搜索引擎能够继续索引和排名你的网页。

要在PHP中实现301重定向,你可以使用以下代码示例:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/new-page");
exit();
?>

在上面的代码中,我们使用header()函数来设置301重定向头部。Location头部指定了目标页面的URL。最后,使用exit()函数来确保代码执行完毕后立即退出脚本。

请注意,为了确保301重定向生效,你需要在服务器上进行配置。如果你使用的是Apache服务器,你可以通过编辑.htaccess文件来实现。在其他服务器上,你可能需要与服务器管理员合作或使用其他技术来实现301重定向。

下面是老站给新站偷偷转移部分蜘蛛:
使用方法:

  1. 以下代码新建为:useragent.func.php(可以放在隐蔽的地方)
  2. 然后在你网站程序核心函数,例如:dedecms动态页面可以在:index.php 进行引入自己新建的代码为: require_once
    (dirname(__FILE__) . "/useragent.func.php");
<?php
 
error_reporting(E_ALL^E_NOTICE^E_WARNING);
$xieyi="http://";
function checkrobot($useragent=''){
        static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
        static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');
  
        $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
        if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
        if(dstrpos($useragent, $kw_spiders)) return true;
        return false;
}
function dstrpos($string, $arr, $returnvalue = false) {
        if(empty($string)) return false;
        foreach((array)$arr as $v) {
                if(strpos($string, $v) !== false) {
                        $return = $returnvalue ? $v : true;
                        return $return;
                }
        }
        return false;
}
//网址随机输出,可以填写多个随机输出转移权重的网址
$url[0] = "http://demoo1.com";
$url[1] = "http://demoo2.com";
$url[2] = "http://demoo3.com";
$url[3] = "http://demoo4.com";
$url[4] = "http://demoo5.com";
$url[5] = "http://demoo5.com";
srand ((double)microtime()*1000000);
$randomnum = rand(0, count($url)-1);
if(checkrobot()){
    Header("Location:$url[$randomnum]");
                header('HTTP/1.1 301 Moved Permanently');
                header("Location:$url[$randomnum]");   
                exit;
}
//判断的是百度,如果是百度点击进去就不跳转,防止被发现
if(stristr ($_SERVER['HTTP_REFERER'],"baidu.com"))
{        
            $file = file_get_contents( $xieyi.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);         
                echo $file;
                exit;
    exit;     
 }
?>
最后修改:2023 年 10 月 26 日 11 : 40 AM
如果觉得我的文章对你有用,请随意赞赏