I'm building a community like a social network or whatever you call. I set a code for all external links so they become not followed links.

Now, I want to code something that allows me to remove the nofollow att from specific domains and add follow att, so I've the option to add quality domains manually in .php to affect all root folders and sub-domains under these specific domains.

The main point is to not treat all domains as spam or not recommended for search engines, Instead I want to simply recommend good and quality domains used by the user in the community to search engines.

The project: http://www.jumzler.com/

A Full sulation, resources, or just headlines will do.

Thank you.

1

There are 1 answers

7
AlphaG33k On BEST ANSWER

Ive set up a client side script using jQuery that I think meets the requirements you requested.

$.setAllowExternalLinksFollowed = function(externalLinkWhitelistArray) {
"use strict";
  var $externalDomLinks = $('a[href^="http"]');
  $externalDomLinks.each(function() {
    var $linkInstance = $(this);
    // Nofollow all ext links
    $linkInstance.attr('rel', 'nofollow');
    externalLinkWhitelistArray.forEach(function(whiteListedUri) {
      if ($linkInstance.attr('href') === whiteListedUri) {
        // Get rid of rel=nofollow from whitelisted links
        $linkInstance.attr('rel', '');
      }
    });
  });
};

Which would be initialized in the views needed like so:

"use strict"
$.setAllowExternalLinksFollowed([
  'http://www.google.com',
  'http://www.cnn.com'
]);

All other external links will have rel="nofollow" in the DOM inspector once this script has a chance to parse and manip the DOM. The whitelisted uri's will instead have the attribute rel="nofollow" truncated to rel="" (or whatever you see fit for your project with minor adjustment).

See it in action with this pen: http://codepen.io/nicholasabrams/pen/qdXWxB

I hope it fits the bill!

PS: If you would like to do this on the server side, you must do it in the area of your backend code where the links are generated, and do a similar comparison to what appears in the jQuery solution offered. Without seeing the backend code that renders/generates the links it would not be feasible to replicate a solution for the serverside (do the links come from an array, or are they static? We have no way of doing anything on the server if the links are static - which they are for all we know based on the OP.