1

I am busy developing a Drupal 7 website. All nodes of content type "X" are displayed on my front page as well as on (possibly) multiple taxonomy term pages. But that is it, users are not allowed to access the single node page directly.

  • I have restricted the user's access to example.com/node/* pages using the plugin "Rabbit Hole nodes", redirecting them to example.com/#node-[node.nid] using the "Token" module.
  • I have also implemented the "Facebook Like Button" module to provide a Like button for each node.

Each of these Like buttons are placed inside a generated iframe with following iframe Src.:

//www.facebook.com/plugins/like.php?href=http%3A%2F%example.com%2Fnode%2F1&layout=button_count&show_faces=true&width=450&font=arial&height=80&action=like&colorscheme=dark&locale=de_DE&send=false

Note: Look at the "href" value that is passed along. It uses the exact URL pattern (../node/*) that I am restricting access to.

I asked myself these questions:

  1. Does the Facebook crawler (user agent: facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php) actually have access to this?
  2. Will "Rabbit hole nodes" not break this like functionality?
  3. Where will users from Facebook land when clicking on the Facebook "like" notification of their friend? I mean, it's restricted..

[Update] How it should actually work:

When accessing the URL example.com/node/1 the following should happen:

  • Normal User (everyone except Facebook's crawler): Should be redirected to example.com/#node-1.
  • Facebook's crawler: Should not be redirected, instead it should just stay on the single node page example.com/node/1.

Possible solution:

  1. One solution that I considered implementing is altering "Rabbit Hole nodes" module code and checking for the Facebook crawler user agent like this:

    if (in_array($_SERVER['HTTP_USER_AGENT'], array(
      'facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)',
      'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
    ))) {
      // Don't execute Rabbit hole functionality
    }
    else {
      // Execute Rabbit hole functionality
    }
    

What are your opinions, ideas and solution approaches?

2 Answers 2

1
+50

Perhaps consider using Page Manager (part of Chaos Tools) to redirect users instead of the Rabbit Hole nodes module.

  1. On the Page Manager admin page (Structure -> Pages) edit the node/%node page
  2. Make a an HTTP response variant that redirects the user to site/#node-NUMBER when they are trying to reach site/node/NUMBER.
  3. Set the selection criteria for that variant depending on the user agent (i.e. don't use this variant when facebook is looking). This will require a custom php rule.

There is an excellent Page Manager tutorial here.

1
  • So, this is exactly what I was looking for! Works like a charm, I obviously cannot test if Facebooks useragent is being redirected or not, but theoretically it should! Thank you! Commented Jan 23, 2015 at 18:14
0
  1. Facebook will not have access if anonymous users do not.
  2. Depends what you mean by 'break'.
  3. Depends on how your Rabbit Hole module is set up. If you set rabbit hole to display a 404 page, this is what people will see.

Hard to offer alternative solutions as you do not explain how you want it to actually function. But altering the Rabbit Hole module is probably not the best way.

2
  • Regarding point 3: Well I am redirecting people to the front page, building a hash URL using a node token, so that they see the wanted node. Looks like this: http://example.com/#node-[node.nid]. Regarding how it should actually function: Keep this redirect functionality for everyone but the Facebook crawler, who should be allowed to access and view the single node page: http://example.com/node/1 Commented Jan 19, 2015 at 9:53
  • (Updated the question) Commented Jan 19, 2015 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.