[SOLVED] Adding "rel=nofollow" to external links in posts?

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Scam Warning
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
User avatar
BucsFan
Registered User
Posts: 253
Joined: Tue Nov 04, 2008 2:41 pm

[SOLVED] Adding "rel=nofollow" to external links in posts?

Post by BucsFan »

Ok heres my dilemma. I want to make all links posted "no follow". I easily found out how to make bbcoded urls into nofollow... but how do I make it so that links NOT posted in "url" tags are nofollow? I'm currently using some coding that makes links open in a new window... so I already know where I'm supposed to add the "nofollow" attribute... I just don't know HOW to add it in this type of coding (PHP). Heres what I mean...

includes/functions_content.php

Code: Select all

        if ($type == MAGIC_URL_EMAIL)
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";    
        }
        else 
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
        } 
includes/functions.php

Code: Select all

      case 'bbcode_htm':
         return array(
            '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
            '#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- l \-\->#',
            '#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- \1 \-\->#',
            '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
            '#<!\-\- .*? \-\->#s',
            '#<.*?>#s',
         );
I need to add the "nofollow" attribute to those two blocks of code. Could someone please re-post those two codes with nofollow correctly added to them please?
Last edited by ric323 on Sat May 16, 2009 4:04 am, edited 2 times in total.
Reason: Topic icon changed
Hostgator - The very best webhosting available on the net
The most reliable uptime - The lowest prices - Excellent tech support
User avatar
BucsFan
Registered User
Posts: 253
Joined: Tue Nov 04, 2008 2:41 pm

Re: Adding "rel=nofollow" to external links in posts?

Post by BucsFan »

Figured it out myself. Google rules! Thanks anyway.
Hostgator - The very best webhosting available on the net
The most reliable uptime - The lowest prices - Excellent tech support
User avatar
Pardis
Translator
Posts: 108
Joined: Sat Jun 21, 2008 11:14 pm

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Pardis »

Dear BucsFan :

Could you share me the method you are used for nofollow please?

Thanks
qu4rk
Registered User
Posts: 33
Joined: Sun Mar 13, 2011 4:47 am

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by qu4rk »

Yes, can you share how you solved this BucsFan?
User avatar
Praetorian Guard
Registered User
Posts: 789
Joined: Wed Oct 07, 2009 12:42 am

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Praetorian Guard »

What exactly does "no follow" do?
User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3510
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by bonelifer »

It was a standard put out by Google, where links marked with it would not get counted in their algorithm determining link relevance and PR score. Basically as far as Google's search bots or any other "rel=nofollow" compliant search bots would be concerned that link just didn't exist. Unfortunately it's not well adopted and where it is it's often misused to on all links.
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Pony99CA »

Pardis wrote:Could you share me the method you are used for nofollow please?
Don't you hate when people do that? If they ask for help, they should put their answer back where they asked.

Anyway, here's my take on how to do it:

First, in includes/functions_content.php, find:

Code: Select all

        if ($type == MAGIC_URL_EMAIL)
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";    
        }
        else 
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\">$text</a><!-- $tag -->$append";
        } 
and replace with:

Code: Select all

        if ($type == MAGIC_URL_EMAIL)
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";    
        }
        else 
        {
            $html    = "$whitespace<!-- $tag --><a$class href=\"$url\" onclick=\"window.open(this.href);return false;\" rel=\"nofollow\">$text</a><!-- $tag -->$append";
        } 
Then, in includes/functions.php, find:

Code: Select all

      case 'bbcode_htm':
         return array(
            '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
            '#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- l \-\->#',
            '#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- \1 \-\->#',
            '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
            '#<!\-\- .*? \-\->#s',
            '#<.*?>#s',
         );
and replace with:

Code: Select all

      case 'bbcode_htm':
         return array(
            '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
            '#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;" rel="nofollow">.*?</a><!\-\- l \-\->#',
            '#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;" rel="nofollow">.*?</a><!\-\- \1 \-\->#',
            '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
            '#<!\-\- .*? \-\->#s',
            '#<.*?>#s',
         );
The above code only works for "magic" URLs (not generated by BBCode). To handle BBCode links, in bbcode.html of your style (if you're using prosilver, this would be the styles/prosilver/template/bbcode.html file), find:

Code: Select all

    <!-- BEGIN url --><a href="{URL}" onclick="window.open(this.href);return false;" class="postlink">{DESCRIPTION}</a><!-- END url -->
and replace with :

Code: Select all

    <!-- BEGIN url --><a href="{URL}" onclick="window.open(this.href);return false;" rel="nofollow" class="postlink">{DESCRIPTION}</a><!-- END url -->
Because this is a template change, you have to refresh your templates.

NOTE: I have not tested any of this, so back up your files before trying this.

Also, the code that the OP posted was that shown in the Links Opening New Windows Knowledge Base article; doing it for stock phpBB code would be similar, but not identical. The KB article will show you the correct code to find for stock phpBB. If you don't want links to open in new windows, just add the code with rel="nofollow" to the stock code the same way as shown above to the appropriate places.

Steve
Last edited by Pony99CA on Sat Jul 02, 2011 1:18 am, edited 1 time in total.
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Pony99CA »

Praetorian Guard wrote:What exactly does "no follow" do?
In addition to what Bonelifer said, Google (and Wikipedia) is your friend. Read Wikipedia's "nofollow" article for an idea of its use and how various search engines handle it.

It's a bit ironic that Google called it "nofollow" but still follows the links. They should have called it "norank" or "noindex".

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by CentaurAtlas »

I also appears there is a mod that will help with the nofollow:

http://www.phpbb.com/community/viewtopi ... #p13011401

The author said it is 3.0.8 compatible too.

I figured since I was searching for the same thing, I'd update the discussion. ;-)
User avatar
Praetorian Guard
Registered User
Posts: 789
Joined: Wed Oct 07, 2009 12:42 am

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Praetorian Guard »

Why would you want a no follow?
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Pony99CA »

Praetorian Guard wrote:Why would you want a no follow?
Did you read bonelifer's response to your original post or the Wikipedia link that I posted?

If so, what don't you understand?

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
User avatar
Praetorian Guard
Registered User
Posts: 789
Joined: Wed Oct 07, 2009 12:42 am

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Praetorian Guard »

Pony99CA wrote:
Praetorian Guard wrote:Why would you want a no follow?
Did you read bonelifer's response to your original post or the Wikipedia link that I posted?

If so, what don't you understand?

Steve

Yes, I read both, but what I do not understand is why a no follow which is basically a no rating. Wouldn't a site want some type of rating through Alexa, etc? Maybe I'm not on the same page or understanding it fully... or is it better to prevent bots and search engine spam? So should all links be a no follow if you want better indexing? I guess I am confused...
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve
Contact:

Re: [SOLVED] Adding "rel=nofollow" to external links in post

Post by Pony99CA »

Praetorian Guard wrote:Yes, I read both, but what I do not understand is why a no follow which is basically a no rating. Wouldn't a site want some type of rating through Alexa, etc?
It wouldn't affect your site's ranking, I wouldn't think; it would affect the sites being linked to from your site. (I would hope that Google doesn't count multiple links from your site to another page on your site in its rankings.)
Praetorian Guard wrote:Maybe I'm not on the same page or understanding it fully... or is it better to prevent bots and search engine spam? So should all links be a no follow if you want better indexing?
I believe that the intent was to keep spambot links on blogs from counting toward their ranking. Of course, it's a broad tool; it also wouldn't count useful links posted by real members.

In phpBB, you might tune it by making links posted by newly registered users nofollow while links posted by registered users wouldn't need that.

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Locked

Return to “[3.0.x] Support Forum”