分享两种外链跳转方法,可避免权重流失。

次阅读

前 2 天,在修改互推联盟自适应页面时,考虑到原先的跳转机制可能会对博友造成困扰,所以想修改成直接跳转模式,彻底抛弃之前强行重写 title 及 iframe 框架的不友好机制。

下面的内容是在研究外链跳转时发现的,感觉还不错,就拿来分享一下!

什么是外链跳转

你或许看见过类似 http://www.***.com/go.php?http://www.******.com 形式的跳转链接,这样是为了站点的 SEO 能够对各种搜索引擎更友好,术语好像就是叫做外链跳转。更重要的是起到了保护自己域名权重的目的。

中间的过渡,很好地避免了外链的导出,又很好地到达了所需的网站,是一个两全其美的好东东。

在这里,我有两种类似的方法,下面一一介绍给大家(仅限于支持 PHP 脚本的服务器),以 WordPress 为例:

方法一:go.php 接收 url 参数

新建一个 go.php 文件,放置到 WordPress 的根目录下,在 go.php 里面输入:

1
<?php header("location:".$_GET["url"]); ?>

然后保存后,可用的外链跳转形式为:{本站地址}/go.php?url={外链地址}。再添加外链的时候,只要给外链加上统一的跳转前缀 http://网站地址/go.php?url= 即可。

方法二:go.php 接收 QUERY_STRING

同样,新建一个 go.php 文件,放置到 WordPress 的根目录下,在 go.php 里面输入:

1
<?php header("location:".$_SERVER['QUERY_STRING']); ?>

然后保存,可用的外链跳转形式为:{本站地址}/go.php?{外链地址}。在添加外链的时候,只要给外链加上统一的跳转前缀 http://网站地址/go.php? 即可。

ASP 环境的等效实现

补充:如果你的主机环境支持 ASP,那么还可以将以下代码存为“go.asp”,起到的效果是一样一样的。

1
2
3
4
5
6
<%
dim url
dim baiyea_url
baiyea_url=request("url")
Response.Redirect baiyea_url
%>

以上内容来自 站长之家。

使用建议与局限

张戈博客采用了第二种跳转方法,速度比嗨酷哥的原始跳转要快得多,而且是直接跳转方式,详见 互推联盟。


以上方法均需要在手动添加外链的时候加上跳转前缀,比如 http://网站地址/go.php?外链地址,并不是很方便。有兴趣的童鞋可以研究下如何写到 functions.php 里面去,强行重写外链。不过 anylink 插件就可以实现这个功能了,所以上面的方法是用于某种特殊情况下的。比如,互推联盟输出成员博客的链接时,就正好可以使用!因为测试 anylink 发现不会生效。

2015-07-16 补充:博客在用的跳转页面代码

有不少朋友留言要我分享张戈博客目前在用的跳转页面代码,好吧,那就分享一下吧!go.php 的代码如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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='/';
	        $title='参数错误,正在返回首页...';
	    }
	}
} else {
    $title='参数缺失,正在返回首页...';
    $url='/';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="1;url='<?php echo $url;?>';">
<title><?php echo $title;?></title>
<style>
body{background:#000}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:50%;left:50%;margin-left:-90px;margin-top: 2px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:36px;font-family:Arial}.spinner{position:absolute;top:50%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}}
</style>
</head>
<body>
<div class="loading">
  <div class="spinner-wrapper">
    <span class="spinner-text">页面加载中,请稍候...</span>
    <span class="spinner"></span>
  </div>
</div>
</body>
</html>

也可以保存为 index.php 文件,然后上传到网站根目录下的 go 文件夹(没有 go 文件夹就新建一个),实现 /go/?url=/ 的跳转形式。

如果想要让评论者链接也弄成这种跳转形式,只要在 WordPress 主题目录下的 functions.php 中插入如下代码即可:

1
2
3
4
5
6
7
//评论者链接重定向
 add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
 add_filter('comment_text', 'add_redirect_comment_link', 99);
 function add_redirect_comment_link($text = ''){
	$text=str_replace('href="', 'href="'.get_option('home').'/go/?url=', $text);
    return $text;
 }

记得代码中的“/go/?url=”需要根据实际使用的跳转形式修改!