0

I would like to redirect my anonymous users to login when they request my Drupal website. I have found many solutions for many themes but not for omega's sub theme. I like my site to limit for authenticated users.

When I used this rule:

{ "rules_test" : {
    "LABEL" : "Test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "init" ],
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      }
    ],
    "DO" : [ { "redirect" : { "url" : "user\/login" } } ]
  }
}

browser shows:

The page isn't redirecting properly.

What 's I missing?

1

Implement a hook_init().

function YOURMODULE_init(){
  global $user;
  if($user->uid == 0){
    drupal_goto('user/login');
  }
}

This will work but if you have cache / reverse proxy cache enabled then you might need to consider about a JS solution too.

  • Thz @heshanlk. I will try. – Mika Jul 9 '13 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.