2

I'd like to block access to all taxonomy pages for anonymous users.

For example I don't want them to be able to view http://website.org/category/year/2525 or http://website.org/taxonomy/term/42.

Is there even some built-in functionality to achieve that? I'm using Drupal 6.

5 Answers 5

4

while category/year/2525 is an alias for taxonomy/term/xxx you should restrict access to taxonomy/term/* for all anonymous users.

if you want do this via simple module:

function mymodule_init(){
  global $user;
  if(arg(0) == 'taxonomy' && arg(1) == 'term' && !$user->uid) {
     drupal_access_denied();
     exit;
  }
}
2

I'm using the Path Access module now. With it I'm blocking the access to the following URLs for anonymous users:

  • category/*
  • taxonomy/*
1

There are various modules that allow you to do this, e.g.

https://www.drupal.org/project/rabbit_hole

Personally, I use Page Manager + Panels. If you enable the Taxonomy term template in the main Panels screen, then edit, you can add a Variant and set the Variant Type to HTTP Response. You can then set selection rules to control when that variant will be applied, e.g.

This panel will be selected if Term being viewed vocabulary is "Package types",
and NOT (Logged in user has role "authenticated user").

This gives you all sorts of control, e.g. per vocabulary, per term, per user role. You could even use this as a way to publish/unpublish term pages by having a boolean field ("Published) and use the value of this field to control whether the term page is accessible.

You can also choose the HTTP response type, such as 301 (redirect someone accessing this to a different page), 403 (resource exists, you don't have access) or 404 (resource doesn't exist).

If you're not already using Panels, I'd probably start with Rabbit Hole and see if it delivers what you want.

0

You can also do this with hook_menu_alter: https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu_alter/7

/**
 * Implements hook_menu_alter.
 * Check access for menu items.
 */
function mymodule_menu_alter(&$items) {
  $items['taxonomy/term/%taxonomy_term']['access callback'] = '_accesscheck';
}

/**
 * Callback to disallow access for the anonymous user.
 */
 function _accesscheck(){
   global $user;
   return $user->uid;
 }
0

Another option in D7 and D8 is the Rabbit Hole module, which provides a variety of options for how to handle default pages/lists, per bundle and per entity.

Your Answer

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