Redirect from one URL to another based on user role 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-&gt;roles))) {
  $dest = $_SERVER['REQUEST_URI'];
  $dest = substr($dest,1); //this removes preceding slash from string
  $path[]='vote'; //example paths to hide from anonymous users...
  $path[]='volunteer';
  $path[]='papers-list';
  $path[]='event-register';
  $path[]='replays-list';
  $path[]='how-to-upgrade';
  $path[]='membership-renewal';

  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.
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.