用過論壇的童鞋們都知道,在帖子內(nèi)容中經(jīng)常會出現(xiàn)外部鏈接,或許演示地址的鏈接,外鏈出現(xiàn)的過多會導(dǎo)致網(wǎng)站權(quán)重降低,在此優(yōu)化就需要給外鏈加上rel="nofollow"屬性提高優(yōu)化效果,因為很多帖子是會員發(fā)的,會員并不知道這個,也不可能讓管理員后期一個個修改,這里給大家介紹一個方法讓系統(tǒng)自動把外鏈都加上nofollow屬性,修改方法如下:
1. 打開目錄source/function/function_discuzcode.php文件,查找parseurl函數(shù),對照以下代碼進行修改:
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函數(shù)后面新增nofollow函數(shù),代碼如下:
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;
}






