Redirect a form just if the form is loaded in specific page(url)
It can be accomplished adding 3 functions to your custom module:

The first one is to implement hook_form_alter():

function my_module_form_alter(&amp;$form, &amp;$form_state, $form_id){
  if($form_id=='user_login') { // It will be executed only on this form.
    // Check if the form is loaded in your custom path.
    if (current_path() == 'my_custom_path') {
      array_push($form['#submit'], 'my_module_login_custom_path_submit');
    }
    else {
      array_push($form['#submit'], 'my_module_login_user_submit');
    }
  }
}


The second one is to implement the redirect to your custom path:

function my_module_login_custom_path_submit(&amp;$form, &amp;$form_state){
  $form_state['redirect'] = 'my_custom_path';
}


The third one is to implement the redirect to user page:

function my_module_login_user_submit(&amp;$form, &amp;$form_state){
  $form_state['redirect'] = 'user';
}