0

I'm attempting to make a simple login page on the front page that once you log in it will route you to your profile. This part I got working with Rules, but if the user clicks the home link on the site at any point, when logged in, I want to route the user to the profile, not the front page.

I tried a similar trigger to the one I got routing a user when they log in. This being on page view trigger when role is not anonymous and URL alias is /node route to user/[account:uid]

When logged in I click the home button and it's not getting triggered. It just sends me to the homepage.

How can I do this with Rules?

1 Answer 1

1

It sounds like there's some missing detail (e.g. checking the right alias, token data not available, etc.).

A simple way to do this to do a page redirect action on a Drupal is initializing event with conditions, Data comparison on [site:current-page:path] & negated User has role(s) on [site:current-user]. Then you can check for the Drupal path that's set for your front page (i.e. '/node').

For example:

{ "rules_login_frontpage_redirect" : {
    "LABEL" : "Logged in Frontpage Redirect to Profile Page",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      },
      { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "node" } }
    ],
    "DO" : [ { "redirect" : { "url" : "user\/[site:current-user:uid]" } } ]
  }
}
3
  • Do you have a page that explains in detail about this example you have? I just want to know how this works so I can build more complex rules as needed. Jul 23, 2016 at 18:35
  • This example looks to work but I don't understand why it works. Jul 23, 2016 at 18:38
  • 1
    The rule says, IF: the internal requested path is /node & the user isn't anonymous on boot up THEN: redirect the current user page, Note, that setting an alias, & setting a path as the front page are two different things. This rule works because /node is set as the default home page. The actual rule path would need to change if it was set to something different.
    – Shawn Conn
    Jul 23, 2016 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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