Deny Access (instead of 404) for non-existant user accounts For a particular project I'm working on, I'd like to return access denied instead of a 404 for non-existant user accounts. I've tried setting a custom 404 page callback and access callback in hook_menu(), and then returning FALSE when paths like user/ are visited, but that doesn't help. I've also tried calling drupal_access_denied() directly in the callback, but that just results in a server error.

I've also tried overriding the user/%user menu item in hook_menu_alter(), but that has no effect on 404 not found pages.

Is there any way to get paths like user/239841239 (any non-existent user ID) to show an access denied page instead of a 404?

[Update: I simply moved the code I was using in the custom 404 page access callback (see below) to the page callback, and now the access denied page is being served correctly.]

// If visiting a non-existent user page, redirect to access denied.
if (strpos(request_path(), 'user/') !== FALSE) {
  drupal_access_denied();
  drupal_exit();
}
I would try setting up a conditional redirect from your 404 page to your custom users-specific error page, that only fires if the path of the referrer is user/*.

I would try to do this using Rules.