I use phpbb3 for this site’s discussion area. It’s not a particularly popular section of the website, but it does attract one type of commenter – spammers.

Spammers like to create posts that link to their own site. They do this for two reasons – one is to drive traffic directly to their site. The other is to increase their Search Engine Results Page ranking (SERP) by adding links to their site.

Search engines use many metrics in determining the position of a page in their search results. One of those is the number of other websites linking in. Because of this, there is a great incentive to create links to one’s own site through spammy comments. This can have a negative impact on the search engine ranking of my own pages, because a site with a lot of spammy links gets categorized as a spammy site by the search engines, and starts to appear lower on the results pages.

I want to continue to let users post useful links, as I think linking can add to a discussion. But I also don’t want to spend a lot of time editing these posts to keep them spam-free. For that reason, I’ve modified phpbb3 to include a ” ‘rel=’nofollow’ ” directive on links posted by users, which tells search engines that they shouldn’t use the fact that my site links to theirs to increase their search engine ranking.

To do so, I had to edit the viewtopic.php file, located in the main phpbb3 directory.

To make the links on your phpbb3 forum automatically have the “nofollow” directive, just search for the following lines, and add preg_replace line, which is #1396 in my example:

   1388    // Second parse bbcode here
   1389    if ($row['bbcode_bitfield'])
   1390    {
   1391       $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
   1392    }
   1393 
   1394    $message = bbcode_nl2br($message);
   1395    $message = smiley_text($message);
 1396    $message = preg_replace('/(class="postlink")/','class="postlink" rel="nofollow" target="_blank"',$message);
   1397