首页课件丨教程安装教程SEO:站外链接正确处理方式含WordPress站外链接跳转(免插件)

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

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

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

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

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

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

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

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

如何正确处理站外链接?

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

示例:

<!- 友情链接 -> <a rel="friend" href="https://www.zhanzhangb.com/">站长帮</a> <!- 帮助文档 -> <a rel="help" href="https://www.zhanzhangb.com/topic-wordpress-tutorial">WordPress教程</a> <!- 相关文档 -> <a rel="bookmark" href="https://www.zhanzhangb.com/615.html">如何处理站外链接</a> <!- 匿名推荐链接 经过此链接访问,目标网页的来源为空 -> <a rel="noreferrer" href="https://www.zhanzhangb.com/615.html">如何处理站外链接</a> <!- 告知搜索引擎不要追踪,或网站不太信任的链接 -> <a rel="nofollow" href="https://www.zhanzhangb.com/615.html">如何处理站外链接</a>

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

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

第一步,在网站根目录下创建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.zhanzhangb.com if($t_url=="zhanzhangb" ) { $t_url="https://www.zhanzhangb.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%20echo%20$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%20echo%20$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>

第二步,添加伪静态规则

Nginx:

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

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.zhanzhangb.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.zhanzhangb.com更改成自己的域名即可。

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

<!- 跳转到站长帮 -> <a href="/go.php?url=https://www.zhanzhangb.com/">跳转到站长帮</a>

声明: 1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:ceo@zunw.cn,我们将第一时间处理! 2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持 3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明。

给TA赏金
共{{data.count}}人
人已赏金
安装教程

WordPressSitemapXML站点地图自定义教程

2022-11-9 23:00:27

安装教程

WordPress建站流程(四)速度优化

2022-11-9 23:00:29

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