3

This is very similar to How do I hide nodes that shouldn't be directly accessed from users and search engines?

I would like to:

  • Not have certain nodes be directly accessible at the full URL (ie. at node/1234 or its alias), since they're being used in a view
  • Make sure they're not being indexed in search engines

My questions are:

  • Does marking a node as "unpublished" have any side effects? other than viewing the node (assuming you're an admin) and seeing the node as unpublished
  • Marking a node as published yields a 401 when its viewed (at its full URL) by anonymous users. Does the page still get crawled? Is there a way to redirect the 401 and not get hurt from a SEO perspective?

EDIT: Using Drupal 7.

Thanks!

  • Are you using Drupal 6 or 7? – user842 Nov 18 '11 at 16:02
  • I'm using Drupal 7. – mmilo Nov 18 '11 at 16:47
1

Not publishing the node means that you can't have works in progress, or you need another way to mark them as not ready for the website. I see this as a definite disadvantage.

Do you mean 403 or 404 instead of 401? If the page results in a 404 then it won't be crawled or indexed. Google has no way to distinguish the "invisible node" case from a plain old bad URL. A 401 should only happen in an authorization case. A 403 may result in a page being revisted at a later date. You never want to redirect from one of these, as this requires a 301 or a 302.

For another way to do this on a legacy project, you can set the path alias to

no-view/[nid]

and then use

function MYMODULE_init ()
{
    $path = drupal_get_path_alias(request_uri());

    if (strpos($path, "no-view/") !== false) {
        drupal_not_found();
        exit;
    }
}

in a custom module. You can wire in similar functionality via the Node API if you want to avoid adding a hook_init().

Moving forward, using entities as suggested by @nicoz is the best idea.

  • For the time being this looks like it'd work. Is it dangerous to have 404s though? If there's ~100 odd nodes that shouldn't be accessible at node/% wouldn't search engines find that strange? – mmilo Nov 18 '11 at 23:07
  • And yes you're right, it's a 403. Search engines may revisit 404's too though.. – mmilo Nov 18 '11 at 23:09
  • Not if the URLs ever got out in the wild. If you are retrofitting, I would put the URLs in .htaccess or httpd.conf (or wherever) and 410 them. That should prevent revists after a while. – mpdonadio Nov 18 '11 at 23:32
3

One of the biggest changes at the architecture level of Drupal 7 is the introduction of entities as an abstraction for content. The old days of trying to cram everything in nodes is over. In short, you get all of the convenience of nodes without the overhead and unnecessary code (and in your case, the architectural challenge of "hiding" nodes from users, crawlers).

Drupal Commerce uses them for products. This allows the products themselves to be inaccessible to end users, but attached to the product displays and views for the end user to see and purchase.

Utilize the Entity Construction Kit (ECK). It will give you a nice UI to create your entities and then just use views to display them for the end-user.

1

The Internal Nodes module should do exactly what you want, though I have not tested it myself.

My only issue with it is that you cannot edit the nodes you hide, but that is being worked on (Allow users to edit/delete nodes they cannot view)

0

If you are not linking to those nodes anywhere on your site then search engines shouldn't even find them.

A more robust approach would be Berdir's suggestion of using hook_node_access.

0

The Rabbit Hole module is awesome for this, you can hide nodes being accessible or re-direct them to a different landing page once. You can choose 'admin' roles to access them normally, and everyone else subject to that generic rule per content type, but also change this on a node by node basis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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