当前位置:首页>网站教程>网站SEO>SEO:站外链接正确处理方式 含WordPress站外链接跳转(免插件)

SEO:站外链接正确处理方式 含WordPress站外链接跳转(免插件)

很多SEO专家都在都在强调,网站的站外链接太多,会造成权重流失。真是这样吗?网站应该如何正确对待站外链接?网站(含WordPress)如何实现经过内链跳转到站外链接?本文为你揭晓答案。

站外链接会造成网站权重流失吗?

首先肯定的是:合理的站外链接对网站权重没有影响,适当的站外链接会更利于SEO

这些站外链接更利于SEO,且提高用户体验:

  • 文章的资料或内容引用的来源链接
  • 相关资料与扩展阅读链接
  • 资料的下载链接
  • 与内容相关领域的推荐内容链接

只有两种情况的站外链接是对SEO不利的:

  • 与网站内容/主题无任何关联性的站外链
  • 低质量的链接目标,包括:目标网页无法问(404、500等)、目标网页有违法、侵权等信息

如何正确处理站外链接?

1、通过rel属性告知搜索引擎,页面与链接的关系

我们可以在HTML脚本中,通过<a>标签的rel属性来告诉搜索引擎链接与页面的关系。

示例:

<!- 友情链接 ->
<a rel="friend" href="https://www.laipang.com/">赖胖网</a>

<!- 帮助文档 ->
<a rel="help" href="https://www.laipang.comp-topic-wordpress-tutorial">WordPress教程</a>

<!- 相关文档 ->
<a rel="bookmark" href="https://www.laipang.com/615.html">如何处理站外链接</a>

<!- 匿名推荐链接 经过此链接访问,目标网页的来源为空 ->
<a rel="noreferrer" href="https://www.laipang.com/615.html">如何处理站外链接</a>

<!- 告知搜索引擎不要追踪,或网站不太信任的链接 ->
<a rel="nofollow" href="https://www.laipang.com/615.html">如何处理站外链接</a>

rel的属性可以同时制定多个值,例如:

<!- 告知搜索引擎不要追踪,且进行匿名推荐 ->
<a rel="nofollow noreferrer" href="https://www.laipang.com/615.html">如何处理站外链接</a><!- 告知搜索引擎不要追踪,且进行匿名推荐 ->
<a rel="nofollow noreferrer" href="https://www.laipang.com/615.html">如何处理站外链接</a>

通过内链跳转站外链接

此方法适用于WordPress建设的网站或其它程序网站,部分资料来源于张戈博客: https://zhang.ge/5086.html

第一步,在网站根目录下创建go.php文件,内容如下:

<?php 
if(strlen($_SERVER['REQUEST_URI']) > 384 ||
    strpos($_SERVER['REQUEST_URI'], "eval(") ||
	strpos($_SERVER['REQUEST_URI'], "base64")) {
		@header("HTTP/1.1 414 Request-URI Too Long");
		@header("Status: 414 Request-URI Too Long");
		@header("Connection: Close");
		@exit;
}
//通过QUERY_STRING取得完整的传入数据,然后取得url=之后的所有值,兼容性更好
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
 
//此处可以自定义一些特别的外链,例如:/go/zhanzhangb跳转到https://www.laipang.com
if($t_url=="laipang" ) {
   $t_url="https://www.laipang.com";
} elseif($t_url=="baidu") {
   $t_url="https://www.baidu.com/";
}
 
//数据处理
if(!empty($t_url)) {
    //判断取值是否加密
    if ($t_url == base64_encode(base64_decode($t_url))) {
        $t_url =  base64_decode($t_url);
    }
    //对取值进行网址校验和判断
    preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$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://'.$_SERVER['HTTP_HOST'];
	        $title='参数错误,正在返回首页...';
	    }
	}
} else {
    $title = '参数缺失,正在返回首页...';
    $url = 'http://'.$_SERVER['HTTP_HOST'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow" />
<noscript><meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"></noscript>
<script>
function link_jump()
{
    //禁止其他网站使用我们的跳转页面
    var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");
    if (!MyHOST.test(document.referrer)) {
         location.href="http://" + MyHOST;
    }
    location.href="<?php echo $url;?>";
}
//延时1S跳转,可自行修改延时时间
setTimeout(link_jump, 1000);
//延时50S关闭跳转页面,用于文件下载后不会关闭跳转页的问题
setTimeout(function(){window.opener=null;window.close();}, 50000);
</script>
<title><?php echo $title;?></title>
<style type="text/css">
body{background:#555}.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:45%;left:50%;margin-left:-100px;margin-top:2px;color:#000;letter-spacing:1px;font-size:20px;font-family:Arial}.spinner{position:absolute;top:45%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:20px solid rgba(255,0,0,1);-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>g

第二步,添加伪静态规则

Nginx:

o# 外链跳转伪静态
rewrite ^/go/(.*)$ /go.php?url=$1 last; #注意go.php的实际路径,默认为网站根目an录

Apache:

RewriteRule ^go/(.*)$ /go.php?url=$1 [L]

第三步,将文章内容与评论的站外链接替换成内链(仅适合WordPress

打开主题的functions.php文件,添加以下内容:

//文章外链跳转
add_filter('the_content','link_jump',999);
function link_jump($content){
	preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
	if($matches){
	    foreach($matches[2] as $val){
	        if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)){
	        $content=str_replace("href=\"$val\"", "href=\"".home_url()."/go/".base64_encode($val)."\" rel=\"nofollow\"",$content);
			}
		}
	}
	return $content;
}
//评论者链接重定向
function commentauthor($comment_ID = 0) {
    $url    = get_comment_author_url( $comment_ID );
    $author = get_comment_author( $comment_ID );
    if ( empty( $url ) || 'http://' == $url ) {
		echo $author;
    } else {
        if (!preg_match(home_url(),$url)) {
            echo "<a href='".home_url()."/go/".base64_encode($url)."' rel='nofollow' target='_blank' class='url'>$author</a>";
        } else {
            echo "<a href='$url' target='_blank' class='url'>$author</a>";
        }
    }	
}

注意,此处如果使用的PHP版本为7.x,可能会提示preg_match出现错误。站长帮修正后的版本:

//评论者链接重定向,站长帮修正版
function zzb_comment_author_link($return, $author, $comment_ID = 0) {
	$comment = get_comment( $comment_ID );
	$url     = get_comment_author_url( $comment );
	$author  = get_comment_author( $comment );
    if ( empty( $url ) || 'http://' == $url ) {
		echo $author;
    } else {
        if (!preg_match("/https:\/\/www.laipang.com/i",$url)) {
            echo "<a href='".home_url()."/g/".base64_encode($url)."' rel='nofollow' target='_blank' class='url'>$author</a>";
        } else {
            echo "<a href='$url' target='_blank' class='url'>$author</a>";
        }
    }	
}
add_filter('get_comment_author_link', 'zzb_comment_author_link', 10 ,3);

将上述代码中的www.laipang.com更改成自己的域名即可。

WordPress网站,可跳过第二步与第三步,通过/go.php?url=URL的方式实现,例如以下链接方式:

<!- 跳转到站长帮 ->
<a href="/go.php?url=https://www.laipang.com/">跳转到站长帮</a>
免责声明 1:本站的课程与素材,都是电子版课件,非实物光盘,课件由百度网盘发送.(百度网盘下载教程)2:本站所有涉及视频及素材,软件等由互联网搜索收集而来,本站不拥有此类资料的版权。3:本站所有视频,素材及软件不加密、不限时、可永久观看或使用!禁止二次销售,否则因此引起的一切问题与本站无关。4:本站所有的资源均为免费提供,提供资料的目的是让大家学习和交流,所收取的相关费用非资料销售费用,而是资料收集整理手工费。5:无意侵害您的权益,请发送邮件至 590173@qq.com 或点击左侧 私信:站长反馈,我们将尽快处理。

给TA打赏
共{{data.count}}人
人已打赏
新手建站

用腾讯云Lighthouse轻量应用服务器,5分钟搞定博客站点打造计划

2023-7-12 12:53:06

网站SEO

SEO教程:帮助新网站搜索引擎找到网站/网页

2023-7-3 1:53:38

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索