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();
}
return MENU_ACCESS_DENIED;
(orreturn MENU_NOT_FOUND;
) instead of callingdrupal_access_denied()
etc