force redirect users to respective sub-site (wordpress multi-site)

does anyone know how to implement code that checks if users are a member of the site and if not, redirect them to their respective sub-site? Essentially, I am trying to restrict logged in users to the sub-site they are registered in, so when they try to access the main site or a different sub-site, they get redirected to their sub-site homepage.