Is there a way to direct unregistered user to registration page when click a link?

It’s simple, use the function is_user_logged_in:

<?php if ( is_user_logged_in() ) { ?>

    <a hef="link-for-logged-users"></a>

  <?php } else { ?> 

    <a hef="link-for-users-not-logged-in"></a>

<?php } ?>

See here http://codex.wordpress.org/Function_Reference/is_user_logged_in

error code: 523