脚本开发,脚本学习,辅助软件,各种工具软件

访问密码统一为:3158

查看: 4224|回复: 0

discuz 给外链统一加上nofollow属性告诉搜索引擎不用追踪

[复制链接]

108

主题

110

帖子

717

积分

专属

Rank: 1

积分
717
发表于 2020-3-16 00:29:03 | 显示全部楼层 |阅读模式
帖子内容中经常会出现外部链接,或许演示地址的链接,外链出现的过多会导致网站权重降低,在此优化就需要给外链加上rel="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));
                }
        $url = nofollow($url);
                return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
        } else {
                $url = substr($url, 1);
                if(substr(strtolower($url), 0, 4) == 'www.') {
                        $url = 'http://'.$url;
                }
                $url = !$scheme ? $_G['siteurl'].$url : $url;
                return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>';
        }
}


2.在parseurl函数后面新增nofollow函数,代码如下:
function nofollow($url = '')
{
    $temp = array();

    if( ! empty($url))
    {
        $temp = parse_url($url);

        if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST'])
        {
            $url .= '" rel="nofollow"';
        }
    }

    unset($temp);
    return $url;
}


3Q4T网,编程学习交流基地。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表