本文主要介绍如何实现自动为站内链接添加"nofollow"实现减少外部链接引起的权重减少问题,本文的内容转自 "博客吧"

以下是实现代码方式:

一、修改模板目录下的module.php,将以下代码放到最后

<?
function content_nofollow($log_content, $domain){
      preg_match_all('/href="(.*?)" rel="external nofollow" /', $log_content, $matches);
      if ($matches) {
      foreach ($matches[1] as $val) {
      if (strpos($val, $domain) === false) {
           $log_content = str_replace('href="' . $val . '" rel="external nofollow"  rel="external nofollow" ', 'href="' . $val . '" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ', $log_content);
            }
        }
    }
       preg_match_all('/src="(.*?)" rel="external nofollow" /', $log_content, $matches);
    if ($matches) {
        foreach ($matches[1] as $val) {
            if (strpos($val, $domain) === false) {
                $log_content = str_replace('src="' . $val . '" rel="external nofollow"  rel="external nofollow" ', 'src="' . $val . '" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ', $log_content);
            }
        }
    }
    return $log_content;
}
?>

二、修改模板目录下的echo_log.php,并找<?php echo $log_content; ?>,替换为以下代码

<?php echo content_nofollow($log_content,BLOG_URL);?>

三、本操作在博客EMBLOG 5.3.1测试通过