Drupal: Login-Screen instead of 403

If you're running a Drupal-based webpage which is completely restricted to authenticated users, Anonymous would get an "403 Access Denied" on every page he tries. But if you want your visitors to see a friendly login page (instead of just this error message and a small "login block") you might want to put the following code into your sites/default/setting.php:

  1. function custom_url_rewrite($op, $result, $path) {
  2. global $user;
  3. if (!$user->uid) {
  4. return "user/login";
  5. }
  6. return $path;
  7. }

You should also check $path if you want to use this on some pages only, e.g. on your frontpage.

UPDATE: This code is erroneous! You should return $result instead of $path, or some other modules like pathauto or path_redirect won't work as expected!