Jump to content

手册:$wgNoFollowLinks

From mediawiki.org
This page is a translated version of the page Manual:$wgNoFollowLinks and the translation is 67% complete.
解析器: $wgNoFollowLinks
若设置为true,在维基文本中的外部链接将被赋予rel="nofollow"属性。
引进版本:1.4.0 (r7174)
移除版本:仍在使用
允许的值:(布尔值)
默认值:true

详情

如果设置为true,在维基文本中的外部链接将会被赋予rel="nofollow"属性,暗示搜索引擎不应该追踪用户提供的链接和垃圾信息的链接,防止影响搜索排名。默认为true。

It may be desirable to configure MW to append rel="nofollow" to internal links that point to pages that haven't yet been written (so-called "red links") for various reasons that include avoiding unnecessary crawler traffic to non-extant pages or for the possibility of improved SEO by avoiding punitive action against a site's ranking due to the presence of "broken links" that aren't broken, just not yet authored.

This may be accomplished by using the HtmlPageLinkRendererEnd hook as follows:

// Add rel="nofollow" to links to pages that don't exist (redlinks)
$wgHooks['HtmlPageLinkRendererEnd'][] = 'noFollowRedLinks';
function noFollowRedLinks(
    $linkRenderer, $target, $isKnown, &$text, &$attribs, &$ret)
{
    if (!$isKnown && preg_match('/\bnew\b/S', $attribs['class'] ?? "")) {
        $attribs['rel'] = 'nofollow';
    }
    return true;
}

另请参阅