论坛优化必备discuz x3.4帖子内容页外链自动加nofollow

云墨
云墨
云墨
647
文章
0
评论
2018年9月6日 评论 1,614

论坛优化必备discuz x3.4帖子内容页外链自动加nofollow

用过论坛的童鞋们都知道,在帖子内容中经常会出现外部链接,或许演示地址的链接,外链出现的过多会导致网站权重降低,在此优化就需要给外链加上rel="nofollow"属性提高优化效果,因为很多帖子是会员发的,会员并不知道这个,也不可能让管理员后期一个个修改,这里给大家介绍一个方法让 系统自动把外链都加上nofollow属性效果,修改方法如下:论坛优化必备discuz x3.4帖子内容页外链自动加nofollow

经下面修改就实现了帖子内容页外链自动加上了nofollow属性,我的网站就这样实现的。

1、打开目录 source/function/function_discuzcode.php 文件,查找parseurl函数,对照以下代码进行修改:

  1. function parseurl($url, $text, $scheme) {
  2.         global $_G;
  3.         if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
  4.                 $url = $matches[0];
  5.                 $length = 65;
  6.                 if(strlen($url) > $length) {
  7.                         $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  8.                 }
  9.                 return 'substr(strtolower($url), 04) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'';
  10.         } else {
  11.                 $url = substr($url, 1);
  12.                 if(substr(strtolower($url), 04) == 'www.') {
  13.                         $url = 'http://'.$url;
  14.                 }
  15.                 $url = !$scheme ? $_G['siteurl'].$url : $url;
  16.                 return ''" target="_blank">'.$text.'';
  17.         }
  18. }

2.在parseurl函数后面新增nofollow函数,代码如下:

  1. function parseurl($url, $text, $scheme){
  2.         global $_G;
  3.         if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
  4.             $url = $matches[0];
  5.             $length = 255;
  6.             if(strlen($url) > $length && strpos(strtolower($url),$_SERVER['HTTP_HOST'])===false) {
  7.                 /*$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));*/
  8.                 $text = $url;/*此处可定义你想要的任何锚文本,如:跳转到外部链接*/
  9.             }
  10.             $url = nofollow($url);/*外链nofollow*/
  11.             return '04) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'';
  12.         }else{
  13.             $url = substr($url, 1);
  14.             if(substr(strtolower($url), 04) == 'www.') {
  15.                     $url = 'http://'.$url;
  16.             }
  17.             $url = !$scheme ? $_G['siteurl'].$url : $url;
  18.             return ''" target="_blank">'.$text.'';
  19.         }
  20. }
  21. /*外链nofollow处理函数*/
  22. function nofollow($url = '') {
  23.     $temp = array();
  24.     if(!empty($url)) {
  25.         $temp = parse_url($url);
  26.         if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST']) {
  27.             if(!preg_match('/(ed2k|thunder|Flashget|flashget|qqdl|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|synacast):\/\//i',$url) && preg_match("/\x20*https?\:\/\/.*/i",$url)&& !preg_match('/\.(webp|svg|jpg|jepg|png|ico|bmp|gif|tiff|mp3|ogg|wma|wav|asf|acc|flac|ape|vqf|swf|mp4|flv|avi|rm|wmv|mov|navi|3gp|ra|ram|mkv|)/i',$val)){ 
  28.                 $url = "http://".$_SERVER['HTTP_HOST']."/goto/".base64_encode($url);
  29.             }
  30.             $url .= '" rel="nofollow"';
  31.         }
  32.     }
  33.     unset($temp);
  34.     return $url;
  35. }

3.跳转页处理base64解码 “go.html”,放置在网站根目录。

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <meta name="robots" content="noindex,nofollow" />
  5. <script>
  6. /*base64加密解密函数*/
  7. var base64EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var base64DecodeChars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,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,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);function base64encode(str){var out,i,len;var c1,c2,c3;len=str.length;i=0;out="";while(i255;if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt((c1&3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt((c2&15)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt(((c2&15)<<2)|((c3&192)>>6));out+=base64EncodeChars.charAt(c3&63)}return out}function base64decode(str){var c1,c2,c3,c4;var i,len,out;len=str.length;i=0;out="";while(ido{c1=base64DecodeChars[str.charCodeAt(i++)&255]}while(i-1);if(c1==-1){break}do{c2=base64DecodeChars[str.charCodeAt(i++)&255]}while(i-1);if(c2==-1){break}out+=String.fromCharCode((c1<<2)|((c2&48)>>4));do{c3=str.charCodeAt(i++)&255;if(c3==61){return out}c3=base64DecodeChars[c3]}while(i-1);if(c3==-1){break}out+=String.fromCharCode(((c2&15)<<4)|((c3&60)>>2));do{c4=str.charCodeAt(i++)&255;if(c4==61){return out}c4=base64DecodeChars[c4]}while(i-1);if(c4==-1){break}out+=String.fromCharCode(((c3&3)<<6)|c4)}return out}function utf16to8(str){var out,i,len,c;out="";len=str.length;for(i=0;iif((c>=1)&&(c<=127)){out+=str.charAt(i)}else{if(c>2047){out+=String.fromCharCode(224|((c>>12)&15));out+=String.fromCharCode(128|((c>>6)&63));out+=String.fromCharCode(128|((c>>0)&63))}else{out+=String.fromCharCode(192|((c>>6)&31));out+=String.fromCharCode(128|((c>>0)&63))}}}return out}function utf8to16(str){var out,i,len,c;var char2,char3;out="";len=str.length;i=0;while(iswitch(c>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:out+=str.charAt(i-1);break;case 12:case 13:char2=str.charCodeAt(i++);out+=String.fromCharCode(((c&31)<<6)|(char2&63));break;case 14:char2=str.charCodeAt(i++);char3=str.charCodeAt(i++);out+=String.fromCharCode(((c&15)<<12)|((char2&63)<<6)|((char3&63)<<0));break}}return out}function doit(){var f=document.f;f.output.value=base64encode(utf16to8(f.source.value));f.decode.value=utf8to16(base64decode(f.output.value))};
  8. /*获取请求参数,支持伪静态*/
  9. function GetQueryString(name){
  10.      var reg = new RegExp("(^|&)"+ name +"=(.*)$");
  11.      var r = window.location.search.substr(1).match(reg);
  12.      if(r!=null) {
  13.          return  unescape(r[2]);
  14.      } else {
  15.          return window.location.pathname.replace('/goto/',''); /*注意代码中的/goto/和跳转地址/goto/保持一致,请记得自行修改!*/
  16.      }
  17. }
  18. var jump_url = GetQueryString("url");
  19. /*若传入的是base加密数据,则进行解密处理*/
  20. if( jump_url == base64encode(base64decode(jump_url))) {
  21.     jump_url = base64decode(jump_url);
  22. }
  23. /*url简单正则*/
  24. var UrlReg = "^((http|https|thunder|qqdl|ed2k|Flashget|qbrowser|ftp|rtsp|mms)://)";
  25. /*自定义一些跳转字符串,请根据实际需求自行发挥*/
  26. if(jump_url=="aliyun") { /*阿里云*/
  27.    var jump_url="https://s.click.taobao.com/t?e=m%3D2%26s%3DmieNRMESxzAcQipKwQzePCperVdZeJviEViQ0P1Vf2kguMN8XjClArWrKYTqxrReim3tltQMB%2B5qyx40EdzqjG6%2BPXQihDCe6bzGtDrAbEhXFUGWrhsf5hVF%2BG%2F2LD3qKIUZKvQyk4%2FkxFiXT%2FI5kdv2ej9RFznDI7hRLPtBsnnfiZ1OxkhRwDBkcElHipW7P37PZ5d3Efk3VTMPr8ftLkWbo0ZyKcLixiXvDf8DaRs%3D";
  28. }
  29. if(jump_url=="qqyun") { /*腾讯云*/
  30.    var jump_url="https://www.qcloud.com/redirect.php?redirect=1001&cps_key=ec918f6669b6c8d3d3a4e67829dc0299";
  31. }
  32. if(jump_url=="zllyun") { /*知了云*/
  33.   var jump_url="https://my.zllyun.com/aff.php?aff=174";
  34. }
  35. if(jump_url=="qiniu") { /*七牛云*/
  36.     var jump_url="https://portal.qiniu.com/signup?code=3llqzltuvrgb6";
  37. }
  38. if(jump_url=="upai") { /*又拍云*/
  39.     var jump_url="https://console.upyun.com/register/?invite=H1rVv0TVZ";
  40. }
  41. if(jump_url=="weibo") { /*微博*/
  42.     var jump_url="https://weibo.com/docnn";
  43. }
  44. /*网址校验*/
  45. if(jump_url == null || jump_url.toString().length<1 || !jump_url.match(UrlReg)) {
  46.     document.title = '参数错误,正在返回首页...';
  47.     jump_url = location.origin;
  48. }
  49. /*延时执行跳转*/
  50. setTimeout(
  51. function link_jump(){ /*非本站域名不允许使用此跳转页面,请自行修改www.docnn.cn为自己的域名,可多个*/
  52.     var MyHOST = new RegExp("blog.docnn.cn"); if (!MyHOST.test(document.referrer) ) { location.href = "//" + MyHOST; return; } location.href = jump_url;
  53. }, 1000);
  54. setTimeout(function(){window.opener=null;window.close();}, 50000);
  55. script>
  56. <title>页面加载中,请稍候...title>
  57. <style type="text/css">
  58. 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}

 

1. 如有链接无法下载、失效或广告,请联系QQ:181289218 处理!
2. 本站的所有资源为购买、网络收集,或者用户投稿的资源,版权归原作者及网站所有!
3. 如若侵犯了您的权利,请及时联系站长删除!
4. 本站提供的资源,都不包含技术服务请大家谅解!
5. 此软件“仅限学习交流,不能用于商业用途”!
6. 如用于商业用途,请到官方购买正版软件,追究法律责任与“云墨SEO”站点无关!
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 站长技术资源群
  • QQ群:431710796
  • weinxin
云墨
  • 本文由 发表于 2018年9月6日
  • 转载请务必保留本文链接:https://www.yunmoseo.com/1656.html
匿名

发表评论

匿名网友