垃圾站 SEO教程:Discuz! X3.2 帖子外链自动添加rel=”nofollow”的方法

SEO教程:Discuz! X3.2 帖子外链自动添加rel=”nofollow”的方法

垃圾站测试用的Discuz!版本是3.2,实际上需要修改的function_discuzcode.php文件并不是每次升级都大改,所以推断Discuz!3.4、3.3、3.1、3.0、2.5甚至之前的老版Discuz!,应该都适用这个方法。

具体教程如下:

第一步, 查找 source/function/function_discuzcode.php文件,用Dreamweaver代码编辑软件打开,查找 function 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>';
}
}

第二步,在parseurl函数后面新增nofollow函数,代码如下:
/* 注释 添加rel="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;
}

修改完成后将文件上传覆盖原文件,打开帖子外链页面查看源代码:
如图:
SEO教程:Discuz! X3.2 帖子外链自动添加rel=”nofollow”的方法插图
已经添加了rel="nofollow" 。

上一篇
下一篇
联系我们

联系我们

返回顶部