WordPress 免插件实现外链转内链 Go 跳转,减少权重流失

<?php 
//$t_url=$_GET['url']; //此代码无法支持带请求参数的目的地址,已弃用!
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]); //这个支持
if(!empty($t_url)) {
    preg_match('/(http|https):\/\//',$t_url,$matches);
        if($matches){
            $url=$t_url;
            $title='页面加载中,请稍候...';
        } else {
            preg_match('/\./i',$t_url,$matche);
            if($matche){
                $url='http://'.$t_url;
                $title='页面加载中,请稍候...';
            } else {
                $url='http://xubiji.com/';
                $title='参数错误,正在返回首页...';
            }
        }
} else {
    $title='参数缺失,正在返回首页...';
    $url='http://xubiji.com/';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="2;url='<?php echo $url;?>';">
<title><?php echo $title;?></title>
<style type="text/css">
a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}body{background:#3498db}#loader-container{width:188px;height:188px;color:#fff;margin:0 auto;position:absolute;top:50%;left:50%;margin-right:-50%;transform:translate(-50%,-50%);border:5px solid #3498db;border-radius:50%;-webkit-animation:borderScale 1s infinite ease-in-out;animation:borderScale 1s infinite ease-in-out}#loadingText{font-family:"Microsoft YaHei",Helvetica,Arial,Lucida Grande,Tahoma,sans-serif,Raleway,sans-serif;font-size:1.4em;position:absolute;top:50%;left:50%;margin-right:-50%;transform:translate(-50%,-50%)}@-webkit-keyframes borderScale{0%{border:5px solid #fff}50%{border:25px solid #3498db}100%{border:5px solid #fff}}@keyframes borderScale{0%{border:5px solid #fff}50%{border:25px solid #3498db}100%{border:5px solid #fff}}
</style>
</head>
<body>
<div id="loader-container"><p id="loadingText">   页面加载中...</p></div>
</body>
</html>

复制代码保存为 index.php 文件,然后上传到网站根目录下的 go 文件夹(没有 go 文件夹就新建一个),实现 http://www.172u.top/go/?url=http://www.172u.top/ 的跳转形式。

更新 robots 规则:
为了防止搜索引擎抓取这种跳转链接,我们可以在robots.txt里面新增禁止抓取/go的规则:

Disallow: /go

此处评论已关闭