I have two pages on my site (created using views) that I would like to hide from anonymous users by redirecting them to a custom access denied page. i.e. If an anonymous user tries to go to the page "wolfdogs/deceased" they are redirected to "access-denied". I found this bit of php that looks promising:

if (in_array('anonymous user', array_values($user->roles))) {
  $dest = $_SERVER['REQUEST_URI'];
  $dest = substr($dest,1); //this removes preceding slash from string
  $path[]='vote'; //example paths to hide from anonymous users...

  if (in_array($dest, $path)) {
    return drupal_goto('members-only'); //this line re-directs to custom access denied page.

Ideally I would like put this into a block, and then put the block on the "hidden" pages. However, it was written for Drupal 6; I don't if it works with Drupal 7, and I am unsure how to implement it into a block.


2 Answers 2


You could also try the Path Access module to restrict access to certain paths based on the users role.


You should be able to restrict the access to the view right from the view edit page. When you are editing the view, change the "Access" setting under the Page Options to allow access based on the Role Authenticated User, which will display an Access Denied page for any anonymous users.

  • The view controls all of my taxonomy term pages, and the pages I want to restrict are 2 terms out of a dozen or more. I did try Taxonomy Access Control, but this module had a lot of unintended consequences that I don't really have the knowledge to work out (menu links and numerous fields disappearing even when users have permission to see them).
    – Seijun
    Commented Aug 21, 2013 at 21:21
  • Ah ok. You could also try the Path Access module (drupal.org/project/path_access) to restrict access to certain paths based on the users role.
    – EJK
    Commented Aug 21, 2013 at 21:30
  • That worked perfectly! I had been looking for a module like that for the past two days but was apparently not using the right search terms. Thank you!
    – Seijun
    Commented Aug 21, 2013 at 21:53
  • No problem, glad it was able to help you out. I added that as an answer, if you could mark it as correct I'd appreciate it!
    – EJK
    Commented Aug 21, 2013 at 22:02

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.