Prevent access to or redirect /user page I'm looking to redirect or prevent access for authenticated users to the /user page. The reason being that it serves no purpose being there so would like to either remove or redirect it.

The best I've managed so far is to redirect the user on login so they don't get dropped on the /user page straight after logging in which works great but I'd like to prevent all access to it. The code I've used for the redirect is below:

function mymodule_user_login($account) {
  // Redirect users on login
  $link = Link::createFromRoute(
    "Admin",
    "admin.home"
  )-&gt;getUrl()-&gt;toString();

  $homeResponse = new RedirectResponse("{$link}");
  $homeResponse-&gt;send();

  return;
}


Just a note for anyone potentially using the above code - it only works in a .module file, not a .theme file which took me a while to work out.
You can probably use access_filter to prevent access to a specific URL.

It can setup filters that will allow you to deny access to specific URL based on IP (or all IPs) and specify where to redirect anyone who is trying to access that URL.