How do you redirect anonymous users to another page without rules? Right now i want to restrict  all anonymous users to a specific page. I know you can do this with rules by setting the condition if they are anonymous have them redirected to another page. But how can this be done via code? Also I need to add exceptions to the redirect as I dont want users redirected out of user/login page, but everywhere else.
I think something like below should work.

function modulename_init() {
  global $user;
  $args = arg();
  if(!user-&gt;uid &amp;&amp; ($args[0] == 'user' &amp;&amp; $args[1] == 'login')) {
    drupal_goto('page_you_want_anony_to_redirect_to');
  }
}