Please add a nofollow attribute to Links like ./user/register ./user/password
why?

  1. first: this prevent a bit spam
  2. second: its useful for seo
  3. thirdly: its very hard for a custom module to inject nofollow attribute
CommentFileSizeAuthor
#3 2086919-3.patch2.11 KBpwolanin

Comments

pwolanin’s picture

Yes, I just was trying to fix this in D7 and there are similar links in comment module that cannot be altered except by hacking core.

pwolanin’s picture

Title: nofollow on Register Links » Add rel=nofollow on Register and Login Links
Priority: Major » Normal
Issue tags: +needs backport to 6.x, +Needs backport to 7.x
pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new2.11 KB

Here's a quick 1st pass at a patch.

Instead or in addition we could add to the HEAD on all these pages:

<meta name="robots" content="noindex">

Note that the way the code is built in comment module is stupidly annoying since this attribute change would come through as a change to a translatable string, making this much less likely to be backportable.

eule’s picture

patch works for me..great & thanks!

"no index" would be nice on pages like https://example.org/filter/tips i think on every drupal sites this causes a bit duplicate content

scor’s picture

If we're going to patch core, why not add these paths to robots.txt directly?

eule’s picture

@scor

disallow in a robots.txt doesn´t mean that any search-engine the path will not be index. it means he has not to crawl it.

Noindex: /filter/tips in a robots.txt means google understand it ..but it it inofficial and maybe bing,yandex or baido don´t understand this...i´m not sure.

noindex on a metatag hits every bot who is knowing the standards. and it means he can crawl it ..but not index.

scor’s picture

You're right @eule, looks like robots.txt doesn't prevent pages from appearing in the search engines index, I wasn't aware of this subtlety. From Google webmaster documentation:

To entirely prevent a page's contents from being listed in the Google web index even if other sites link to it, use a noindex meta tag or x-robots-tag. As long as Googlebot fetches the page, it will see the noindex meta tag and prevent that page from showing up in the web index.

So it looks like what we need is an explicit:

<meta name="robots" content="noindex">

in the HTML, as I don't think that adding a nofollow will be sufficient either. This is particularly true if there are other links pointing to these pages, including external sites.

scor’s picture

Title: Add rel=nofollow on Register and Login Links » Add content="noindex" meta element on Register and Login pages

updating title. Note that this is what wordpress does for example: http://wordpress.com/wp-login.php

eule’s picture

if someone give some tips / hints i will dig into it

scor’s picture

Either (1) the user module could implement HOOK_preprocess_html() and execute drupal_add_html_head() if the path is '/user/login' or '/user/register'. OR (2) you could add a drupal_add_html_head() inside the respective form builders '\Drupal\user\Form\UserLoginForm' and 'user.register'. I'm not sure which one is kosher in D8.

eule’s picture

get it not working ;(
need the pros!

eule’s picture

Hello,

i try this in .core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php

  // Prevent user/register from being indexed
  $noindex_meta_tag = array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'robots',
      'content' => 'noindex, follow',
    ),
  );
  drupal_add_html_head($noindex_meta_tag, 'install_meta_robots');

but it is still not working :-) maybe i put it in the wrong file or position?
any one with help please?

scor’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -

Some sites might want to have their user/register form indexed I think.

eule’s picture

then makes an option for the admins who don´t want it

xjm’s picture

eule’s picture

This issue (feature) is now 2 years old! D8 is out..and nothing is done...simply...thats the drupal way..late always tooo late

xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev

Since this breaks strings, it's not eligible for 8.0.x at this point. However, a site-specific workaround in that case might be to provide a custom translation of the string that adds the nofollow.

@eule, your comment is not helpful. You can help this issue make progress by testing the actual patch provided and confirming whether that works. See https://www.drupal.org/patch/apply for help on how to apply patches.

It sounds like we should also remove the user login block change from this patch according to @scor's review. https://www.drupal.org/node/707484 explains how you can create a new patch, and https://www.drupal.org/node/1488712 explains how you can create an interdiff to show a change from a previous patch. You can also come to the Drupal core mentoring hours to get help with contributing to a core issue. See https://www.drupal.org/core-mentoring for more information.

Finally, @eule, since we may not make the user login block change in core, I think a good way to provide a fix for the user login block would be to create a contributed or custom module that provided an alternate user login block with the nofollow option. Then sites that wanted the nofollow could place that block instead.

Thanks!

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andraeray’s picture

I accomplished it this way by using a preprocess_page hook in template.php. It checks requested URL to see if it has /user/ at the beginning.

function MY_THEME_preprocess_page(&$variables) {

  $robots_noindex = array (
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'name' =>  'robots',
      'content' => 'noindex',
    ),
  );

$url_parts = explode('/', request_uri());
  
  if($url_parts[1] == 'user') {
    drupal_add_html_head($robots_noindex, 'no_index_rsvp');

  }

}

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

b.livonnen’s picture

Usefull piece of code @AndraeRay
You can modify it this way to handle sites in subfolders as well :

$url_parts = explode ( '/', request_path () );
	
if ($url_parts [0] == 'user') {
	drupal_add_html_head ( array (
			'#type' => 'html_tag',
			'#tag' => 'meta',
			'#attributes' => array (
					'name' => 'robots',
					'content' => 'noindex' 
			) 
	), 'no_index_rsvp' );

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Pejka’s picture

You can use this piece of code in html.html.twig

{% set url = url('') %}
{% if 'user' in url|render|render %}
meta name="robots" content="noindex" (add <> since those are hidden by drupal.org editor)
{% endif %}

What I suggest is to install drupal/rename_admin_paths module and change /user/* url. After that configure this code to check for new keyword in url string.
Be aware that in order for this to work, your url should not be in robots.txt: https://developers.google.com/search/reference/robots_meta_tag

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

caspervoogt’s picture

None of the code suggestions in the thread above worked for me. I solved it using metatag_routes.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bbombachini’s picture

In D8 you can also do it through a hook_page_attachments_alter and use path.matcher service to add to all /user pages like this:

/**
 * Implements hook_page_attachments_alter.
 */
function theme_page_attachments_alter(array &$attachments) {

  $current_path = \Drupal::service('path.current')->getPath();
  $patterns = '/user/*';
  $match = \Drupal::service('path.matcher')->matchPath($current_path, $patterns);

  $noindex = [
     '#tag' => 'meta',
     '#attributes' => [
        'name' => 'robots',
        'content' => 'noindex',
      ],
  ];

  if($match) {
    $attachments['#attached']['html_head'][] = [$noindex, 'description'];
  }
}

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jungle’s picture

Status: Needs work » Closed (won't fix)

https://www.drupal.org/project/metatag_routes mentioned in #27 by @caspervoogt works as expected, and I do not think we should bring this into the core. So let's close this. Thanks all for your efforts!