论坛优化必备discuz x3.4帖子内容页外链自动加nofollow
用过论坛的童鞋们都知道,在帖子内容中经常会出现外部链接,或许演示地址的链接,外链出现的过多会导致网站权重降低,在此优化就需要给外链加上rel="nofollow"属性提高优化效果,因为很多帖子是会员发的,会员并不知道这个,也不可能让管理员后期一个个修改,这里给大家介绍一个方法让 系统自动把外链都加上nofollow属性效果,修改方法如下:
经下面修改就实现了帖子内容页外链自动加上了nofollow属性,我的网站就这样实现的。
1、打开目录 source/function/function_discuzcode.php 文件,查找parseurl函数,对照以下代码进行修改:
- function parseurl($url, $text, $scheme) {
- global $_G;
- if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
- $url = $matches[0];
- $length = 65;
- if(strlen($url) > $length) {
- $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
- }
- return 'substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'';
- } else {
- $url = substr($url, 1);
- if(substr(strtolower($url), 0, 4) == 'www.') {
- $url = 'http://'.$url;
- }
- $url = !$scheme ? $_G['siteurl'].$url : $url;
- return ''" target="_blank">'.$text.'';
- }
- }
2.在parseurl函数后面新增nofollow函数,代码如下:
- function parseurl($url, $text, $scheme){
- global $_G;
- if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
- $url = $matches[0];
- $length = 255;
- if(strlen($url) > $length && strpos(strtolower($url),$_SERVER['HTTP_HOST'])===false) {
- /*$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));*/
- $text = $url;/*此处可定义你想要的任何锚文本,如:跳转到外部链接*/
- }
- $url = nofollow($url);/*外链nofollow*/
- return '0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'';
- }else{
- $url = substr($url, 1);
- if(substr(strtolower($url), 0, 4) == 'www.') {
- $url = 'http://'.$url;
- }
- $url = !$scheme ? $_G['siteurl'].$url : $url;
- return ''" target="_blank">'.$text.'';
- }
- }
- /*外链nofollow处理函数*/
- function nofollow($url = '') {
- $temp = array();
- if(!empty($url)) {
- $temp = parse_url($url);
- if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST']) {
- 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)){
- $url = "http://".$_SERVER['HTTP_HOST']."/goto/".base64_encode($url);
- }
- $url .= '" rel="nofollow"';
- }
- }
- unset($temp);
- return $url;
- }
3.跳转页处理base64解码 “go.html”,放置在网站根目录。
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="robots" content="noindex,nofollow" />
- <script>
- /*base64加密解密函数*/
- 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))};
- /*获取请求参数,支持伪静态*/
- function GetQueryString(name){
- var reg = new RegExp("(^|&)"+ name +"=(.*)$");
- var r = window.location.search.substr(1).match(reg);
- if(r!=null) {
- return unescape(r[2]);
- } else {
- return window.location.pathname.replace('/goto/',''); /*注意代码中的/goto/和跳转地址/goto/保持一致,请记得自行修改!*/
- }
- }
- var jump_url = GetQueryString("url");
- /*若传入的是base加密数据,则进行解密处理*/
- if( jump_url == base64encode(base64decode(jump_url))) {
- jump_url = base64decode(jump_url);
- }
- /*url简单正则*/
- var UrlReg = "^((http|https|thunder|qqdl|ed2k|Flashget|qbrowser|ftp|rtsp|mms)://)";
- /*自定义一些跳转字符串,请根据实际需求自行发挥*/
- if(jump_url=="aliyun") { /*阿里云*/
- var jump_url="https://s.click.taobao.com/t?e=m%3D2%26s%3DmieNRMESxzAcQipKwQzePCperVdZeJviEViQ0P1Vf2kguMN8XjClArWrKYTqxrReim3tltQMB%2B5qyx40EdzqjG6%2BPXQihDCe6bzGtDrAbEhXFUGWrhsf5hVF%2BG%2F2LD3qKIUZKvQyk4%2FkxFiXT%2FI5kdv2ej9RFznDI7hRLPtBsnnfiZ1OxkhRwDBkcElHipW7P37PZ5d3Efk3VTMPr8ftLkWbo0ZyKcLixiXvDf8DaRs%3D";
- }
- if(jump_url=="qqyun") { /*腾讯云*/
- var jump_url="https://www.qcloud.com/redirect.php?redirect=1001&cps_key=ec918f6669b6c8d3d3a4e67829dc0299";
- }
- if(jump_url=="zllyun") { /*知了云*/
- var jump_url="https://my.zllyun.com/aff.php?aff=174";
- }
- if(jump_url=="qiniu") { /*七牛云*/
- var jump_url="https://portal.qiniu.com/signup?code=3llqzltuvrgb6";
- }
- if(jump_url=="upai") { /*又拍云*/
- var jump_url="https://console.upyun.com/register/?invite=H1rVv0TVZ";
- }
- if(jump_url=="weibo") { /*微博*/
- var jump_url="https://weibo.com/docnn";
- }
- /*网址校验*/
- if(jump_url == null || jump_url.toString().length<1 || !jump_url.match(UrlReg)) {
- document.title = '参数错误,正在返回首页...';
- jump_url = location.origin;
- }
- /*延时执行跳转*/
- setTimeout(
- function link_jump(){ /*非本站域名不允许使用此跳转页面,请自行修改www.docnn.cn为自己的域名,可多个*/
- var MyHOST = new RegExp("blog.docnn.cn"); if (!MyHOST.test(document.referrer) ) { location.href = "//" + MyHOST; return; } location.href = jump_url;
- }, 1000);
- setTimeout(function(){window.opener=null;window.close();}, 50000);
- script>
- <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}
1. 如有链接无法下载、失效或广告,请联系QQ:181289218 处理!
2. 本站的所有资源为购买、网络收集,或者用户投稿的资源,版权归原作者及网站所有!
3. 如若侵犯了您的权利,请及时联系站长删除!
4. 本站提供的资源,都不包含技术服务请大家谅解!
5. 此软件“仅限学习交流,不能用于商业用途”!
6. 如用于商业用途,请到官方购买正版软件,追究法律责任与“云墨SEO”站点无关!
2. 本站的所有资源为购买、网络收集,或者用户投稿的资源,版权归原作者及网站所有!
3. 如若侵犯了您的权利,请及时联系站长删除!
4. 本站提供的资源,都不包含技术服务请大家谅解!
5. 此软件“仅限学习交流,不能用于商业用途”!
6. 如用于商业用途,请到官方购买正版软件,追究法律责任与“云墨SEO”站点无关!
- 我的微信
- 这是我的微信扫一扫
-
- 站长技术资源群
- QQ群:431710796
-
评论