Your module could intercept the value of "Default 403 (access denied) page
" which is modified by the page "Administer > Site configuration > Error reporting
":
In
hook_enable
, usingvariable_get
/variable_set
, copy the existing value to a secondary variable and replace the variable by your own path (which you registered usinghook_menu
).alter the "Error reporting" form using
hook_form_FORM_ID_alter
to read from/write to the secondary variableIf you want to be completely invisible to the user, your page callback to could call
drupal_goto( the_value_of_the_secondary_variable )
.In
hook_disable
, restore the value from the secondary variable.
And that's it, your module gets notified in a clean way (and invisible to the user) when "Access denied" is triggered.