论坛 SEO 必备良品。
如果帖子中过多的外链会分散了该页面的权重,这样是不利于网站排名的。所以网站内页最好是尽量不要链接向外部。
但是在某些情况下我们不得不链接向外部,那么该如何处理呢?其实我们可以给外部链接加上 nofollow 属性,这样有效仿止搜索权重的流失,对 SEO 优化起到一个很好的作用。
下面修改的作用就是,自动给帖子链接添加 nofollow 属性。
以 discuz X3 为例:
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 = !$scheme ? $_G['siteurl'].$url : $url;
- return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>';
- }
- }
2、在该代码块下方空一行,添加以下代码
- function nofollow($url = ''){
- $temp = array();
- if( ! emptyempty($url))
- {
- $temp = parse_url($url);
- if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST'])
- {
- $url .= '" rel="nofollow"';
- }
- }
- unset($temp);
- return $url;
- }
完毕!
评论 (0)