redirect after incorrectly login

By tobi

I have found out how to redirect the user to an other page after Login

elgg_register_event_handler('login', 'user', 'after_login_redirect');
function after_login_redirect($event, $type, $user) {
    $url = elgg_get_site_url()."profile/".$user->username;
    forward($url);
}

 

But how can I redirect the user after incorrectly login to the registration-page?

And also I am looking for a possibility to redirect the user to the registration page, if he is not loggedin and try to watch a page for only loggedin useres (at the moment the redirect goes to the startpage)

Thanks in advance

Tobi