Redirect user page to user/edit and user/login I want to do page redirect when user access /user page. When user anonymous user access the /user it should redirect to user/login page and when logged in user access the /user page it should redirect to user/%/edit page.

I have tried the following the code

function my_user_menu_alter(&amp;$items){
   $items['user']['page callback'] = 'my_user_page_redirect';
} 
function my_user_page_redirect() {
  global $user;
  if (user_is_logged_in()) {
  drupal_goto('user/'.$user-&gt;uid.'/edit');
}
 else {
   drupal_goto('user/login');
 }

}


For logged in user it redirects to user/%/edit page. For anonymous user it displays webpage redirect error

How can I do this. Thank You
You can do it without hook_menu_alter, achieve it in hook_init, try something like  (don't forget changes in hook_init need clear the cache to getting applied)

function yourmodule_init(){
   if(current_path()=="user"){
   global $user;
     if (user_is_logged_in()) {
      drupal_goto('user/'.$user-&gt;uid.'/edit');
    }
   else {
      drupal_goto('user/login');
   }
}
}