If I created content that is of "basic page" content type that is mapped to a URL path settings as an alias how would I restrict access to that page to only 1 role?

If the user is not logged on then how can I redirect the user to a login page and then after that send them back page to the originally requested page?

Note I only want to restrict access for this one page and not all pages that have "basic page" content type.

3 Answers 3


Use hook_node_view()

function mymodule_node_view($node, $view_mode, $langcode) {
  $user = $GLOBALS['user'];
  // Check user->roles
  // If user hasn't access to current node
  drupal_set_message(t('You have to login before continue...'), 'status');
  drupal_goto('user', array('query' => array('destination' => 'node/' . $node->nid)));


The Anonymous Login module will intercept restricted page requests from anonymous users, give them a login form, then take them back to the requested page when they are logged in.

You can certainly restrict access to a single role on a particular page using Content access. Just go to the Access Control tab of the content type and check 'Enable per content node access control settings '.

The problem as I see it is that the drupal menu system checks a user's access permissions before displaying a menu item, so your anonymous users and the users without the restricted role will never be able to go to the restricted content through a menu item. The only way to direct them to the content is through a hard coded link in a page or an email.


This can be acheived by using a combination of content access and login toboggan modules. You'll be able to restrict pages and prompt user to login to access them.

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.