This is an example on how to handle a user redirection with a custom logic using an event subscriber inherited by Drupal from the Symfony framework
npinos/drupal_redirect_user_event_subscriber
Example module for redirecting anonymous users to a custom login url
PHP