Manual:$wgNoFollowLinks/zh

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<translate> Parser</translate>: $wgNoFollowLinks
若设置为true,在维基文本中的外部链接将被赋予rel="nofollow"属性。
<translate> Introduced in version:</translate>1.4.0 (r7174)
<translate> Removed in version:</translate><translate> still in use</translate>
<translate> Allowed values:</translate>(布尔值)
<translate> Default value:</translate>true

详情

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

Setting nofollow for red links

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;
}

另请参阅