1回答

0收藏

Discuz X3.5帖子内容中的外部链接加上rel=nofollow方法是什么

后端开发 后端开发 39 人阅读 | 1 人回复 | 2024-03-20

本帖最后由 求知者 于 2024-3-20 11:52 编辑

帖子里的外链 a标签居然没有 rel="nofollow",对SEO很不友好,有什么方法能添加rel="nofollow"属性?
关注下面的标签,发现更多相似文章
"打赏他人,曝光自己,利他利我"
还没有人打赏,支持一下

回答|共 1 个

大神

发表于 2024-3-20 11:48:00 | 显示全部楼层

给Discuz! 帖子外链自动添加nofollow的方法


打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改:

  1. function parseurl($url, $text, $scheme) {
  2.         global $_G;
  3.         if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
  4.                 $url = $matches[0];
  5.                 $length = 65;
  6.                 if(strlen($url) > $length) {
  7.                         $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  8.                 }
  9.                 $nofllow = strpos($url, $_G['siteurl']) !== 0 ? '" rel="nofollow' : ”;  
  10.                 return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).$nofllow.'" target="_blank">'.$text.'</a>';
  11.         } else {
  12.                 $url = substr($url, 1);
  13.                 if(substr(strtolower($url), 0, 4) == 'www.') {
  14.                         $url = 'http://'.$url;
  15.                 }
  16.                 $url = !$scheme ? $_G['siteurl'].$url : $url;
  17.                 $nofllow = strpos($url, $_G['siteurl']) !== 0 ? '" rel="nofollow' : ”;  
  18.                 return '<a href="'.$url.$nofllow.'" target="_blank">'.$text.'</a>';
  19.         }
  20. }
复制代码


还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则