I would like to add nofollow to some internal links on my site like register and request new password.
How could I accomplish that? I followed direction found on: http://www.dandurick.com/blog/guide-drupal-seo and modified user.module, but with no success, the links didn't receive rel="nofollow". Any ideas?

Comments

Bobby1290’s picture

sedmi’s picture

It is excellent solution for links that are in menu, but can I add rel="nofollow" to register, request new password, syndicate links with it?

Bobby1290’s picture

Not like that, there are several requests for it.
There is a nofollow module that got left behind, you could try to update it to Drupal 6.x.

To lower the importance of "service" pages;
-Move all service links to their own menu or block and make them nofollow (the block way means one less module). After that disable them in public menus.
-You could dump your db to sql, change the references there and reupload.(not always possible or wanted)
-don't create service links in content, always make reference to these links by pointing to the "service links block/menu"
-change your theme to add the nofollow to the service links as they are displayed (my preferred option).

This can mitigate the impact of having service links on all your pages.

sedmi’s picture

Could you tell me more about "-change your theme to add the nofollow to the service links as they are displayed (my preferred option)."
Should I modify page.tpl.php? And how? I don't have much experience with php.

Bobby1290’s picture

You'll have to dig into php for this.

In my view there are roughly 2 options.

1. Brute Force.
In node.tpl.php scan and replace the <a href="linkyouwanttochange">....</a> with <a href="linkyouwanttochange" rel="nofollow">....</a> in the $links string with any of the php string replace functions (for example http://us3.php.net/str_replace or http://us3.php.net/manual/en/function.substr-replace.php). Of course first check in the source how the link is coded.
This is not the preferred "drupal way", but it should not give major problems with updates.

2. Drupal Way.
Find the function that outputs the links you want to change and override the function in template.php of your theme.
For example:
The "login or register to post comments" link is themed in the comment.module with the following function:

/**
 * Theme a "you can't post comments" notice.
 *
 * @param $node
 *   The comment node.
 * @ingroup themeable
 */
function theme_comment_post_forbidden($node) {
  global $user;
  static $authenticated_post_comments;
  
  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {
      // We only output any link if we are certain, that users get permission
      // to post comments by logging in. We also locally cache this information.
      $authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval'));
    }
    
    if ($authenticated_post_comments) {
      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_'. $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = 'destination='. drupal_urlencode("comment/reply/$node->nid#comment-form");
      }
      else {
        $destination = 'destination='. drupal_urlencode("node/$node->nid#comment-form");
      }

      if (variable_get('user_register', 1)) {
        // Users can register themselves.
        return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
      }
      else {
        // Only admins can add new users, no public registration.
        return t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
      }
    }
  }
}

Add this function to your themes template.php as:

/**
 * Theme override for "you can't post comments" notice.
 *
 * @param $node
 *   The comment node.
 * @ingroup themeable
 */
function phptemplate_comment_post_forbidden($node) {
  global $user;
  static $authenticated_post_comments;
  
  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {
      // We only output any link if we are certain, that users get permission
      // to post comments by logging in. We also locally cache this information.
      $authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval'));
    }
    
    if ($authenticated_post_comments) {
      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_'. $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = 'destination='. drupal_urlencode("comment/reply/$node->nid#comment-form");
      }
      else {
        $destination = 'destination='. drupal_urlencode("node/$node->nid#comment-form");
      }

      if (variable_get('user_register', 1)) {
        // Users can register themselves.
        return t('<a rel="nofollow" href="@login">Login</a> or <a rel="nofollow" href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
      }
      else {
        // Only admins can add new users, no public registration.
        return t('<a rel="nofollow" href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
      }
    }
  }
}

You will have to override all the link theming functions that you want to contain the "nofollow" attribute.
You can also add the nofollow to the attribute array as 'rel' => t('nofollow').

Hope this helps.

tab.khan’s picture

Hello Sedmi i would like to do the same things you wanted to do years back. I want to 'unfollow' some internal links just like register, my account and others so if you were able to do this and you can guide me through that would be great

rocktanvira3’s picture

Thanks, I was finding this solution.

alexanderpas’s picture

actually, adding rel="nofollow" to those links is completely unneeded since those paths are already in robots.txt
all search engines etc. will follow those instructions and thus never even visit those pages
if you add an alias to those pages, just add them to robots.txt yourself and search engines won't visit them.
see for an example: http://drupal.org/robots.txt

less == more

sedmi’s picture

Yes, spiders won't index them, but page rank will flow and I don't want that. I understand that there are a lot of people who think that it is not good thing to nofollow that kind of "unimportant" links, but I am one of those who favor nofollowing all links that aren't related to actual content. There are lot of places on internet where debates about that can be found, I think this thread is not place for debate whether it should be done, but for solution for those who do want to nofollow those links.

Bobby1290’s picture

A Google search for register at drupal http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen... shows that the drupal registration page is the highest ranked one, and that is what he wants to avoid (if not, that is what I would want to avoid).

Note that drupal.org/user/register is the first result AND is blocked in robots.txt. (maybe a refinement to robots.txt will help)
Also note that robots.txt and nofollow are mere "suggestions".

robots.txt and nofollow do related but separate things. To make a page less important, nofollow is the google acknowledged way (if that exists).