Core: Internal forum links behavior, nofollow, target _blank

Created on 5 Nov 2015  路  9Comments  路  Source: flarum/core

Have local links (a link to another topic, tag, anything from within the same forum) open in the same tab/window.

typfeature

All 9 comments

We have discussed and agree that this is worth implementing, along with some styling for external links to indicate they will open in a new window (e.g. https://discuss.flarum.org/d/1645-external-link-styling)

From #1151.

Absolutely agree with @quangpkv. Internal links should not use nofollow attribute. Explained by Matt Cutts (former head of the webspam team at Google) here, here and here. However, use nofollow for external links is a correct antispam measure (IMHO).

Edit. Agree also with @Fastidious. The current target=_blank attribute for internal links is annoying for the navigation.

@Luceos Can you edit the issue title? Internal links is better than Local links (more useful for searches).

For reference: @Zeokat's post from #1173:

Flarum adds rel="nofollow" attribute to all links posted, it's a serious issue that damage website SERPs and don't follow SEO best practices.

It was discussed many times into Flarums forum, for example here but the problem seems that can't be fixed easily at this development stage.

Flarum "views" every link posted into a discussion as external and that's a wrong concept when we speak about SEO. External and internal domains are related to the domain. For example into https://discuss.flarum.org/ all urls that works under main domain https://discuss.flarum.org/ must be internal links. This guarantees a proper link juice flow into the community.

At the moment, all forum software tested works in this way (MyBB, phpBB, NodeBB, etc...) and Flarum also should adopt this good SEO practice.

In some situations other subdomains and main domain (for example https://flarum.org/ , https://docs.flarum.org/, etc) can be handled as internal links, but maybe this situations should be handled by an extension instead core.

If/when this becomes revisited, it also makes sense to NOT include ref="nofollow" when the link is posted by a mod/admin since this is an antispam measure to begin with.

Half of this was taken care of in https://github.com/flarum/core/issues/859#issuecomment-535715177 yesterday, but the removal of nofollow for internal links still needs to be taken care of.

Does the new rel="ugc" have the same problem? Semantically, that seems more correct here.

As discussed in yesterday's meeting, we want to remove nofollow from all internal links, and will close this issue when that is implemented.

target=_blank will no longer be part of core starting with beta.11 (see #859) - there is now a replacement extension.

@JoshyPHP Does TextFormatter already differentiate between "internal" and "external" links? As far as I understand, the "configurator" is used only when precompiling the runtime components and generates templates for the URLs used in parsing / rendering. So we would need two different templates here?

No, there's no differentiation. You'd need to do that at parsing time with a tag filter that indicates which kind of link this is, and/or at rendering time by doing the same thing with s9e\TextFormatter\Utils::replaceAttributes().

$configurator = new s9e\TextFormatter\Configurator;
$configurator->Autolink;

$tag = $configurator->tags['URL'];
$tag->attributes->add('type')->required = false;
$tag->filterChain->append('markLinks($tag, /^https?:\\/\\/[^\\/]*\\bexample.org/)')
    ->setJS("
        function (tag, regexp)
        {
            var type = regexp.test(tag.getAttribute('url')) ? 'internal' : 'external';
            tag.setAttribute('type', type);
        }
    ");

function markLinks($tag, $regexp)
{
    $type = preg_match($regexp, $tag->getAttribute('url')) ? 'internal' : 'external';
    $tag->setAttribute('type', $type);
}

$tag->template = '<a href="{@url}">
    <xsl:if test="@type = \'external\'">
        <xsl:attribute name="rel">noreferrer</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
</a>';

extract($configurator->finalize());

$text = "https://example.org\nhttps://notexample.org";
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

die($html);
<a href="https://example.org">https://example.org</a>
<a href="https://notexample.org" rel="noreferrer">https://notexample.org</a>
Was this page helpful?
0 / 5 - 0 ratings