Last updated 28 May 2009. Created on 23 May 2007.
Edited by bekasu, LeeHunter, add1sun, chx. Log in to edit this page.

  1. Make 'denied' the 403 page.
  2. While you could pull the login form as the login block does and 4.7 and onwards it automatically submits -- but the registration tab would not appear. Solving this is very difficult, see for further details (D6 solved this by rehauling the menu system from ground up). Add this to any hook_menu implementation in the $may_cache part. This is extremely important, this part must be cached.
        $items[] = array(
          'access' => !$user->uid,
          'path' => 'denied',
          'callback' => 'mymodule_denied',
          'type' => MENU_CALLBACK,
  3. To your module, add:
    function mymodule_denied() {
      global $user;
      if ($user->uid) {
        return t('Access denied');
      drupal_goto($_GET['q'], 'login=1');
  4. To settings.php add
    function custom_url_rewrite($op, $result, $path) {
      if ($op == 'source' && !empty($_GET['login'])) {
        return 'user/login';
      return $result;

Another Option

Another way of doing this is with panels.

Looking for support? Visit the forums, or join #drupal-support in IRC.