I have a Drupal 7 installation. In my homepage I have only two forms (login and register) so I need when someone leaves the site and the user is logged in, when he visits it again that he redirect to another page (similar to Facebook functionality).

Currently the user is redirected to user profile page.

I tried to use Rules and I put in Rules Event 'Drupal is initializing', in Rules Condition path to 'check=[site:url]' to be redirected but with no effect.

Any ideas?

1 Answer 1


Not sure if it will be your only problem to be fixed, but you seem to be using the wrong token in your condition path. Try again using either of these tokens:

  • [site:current-page:path].
  • [site:current-page:url].

Below is an example of a rule (in Rules Export format) which illustrates how to use either of these tokens:

{ "rules_redirect_logged_in_user" : {
    "LABEL" : "Redirect logged in user",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
      { "OR" : [
          { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "node\/123" } },
          { "text_matches" : { "text" : [ "site:current-page:url" ], "match" : "something" } }
    "DO" : [
      { "drupal_message" : { "message" : "Using the path [site:current-page:path] (or url [site:current-page:url]) makes no sense for authenticated users, which is why you are redirected ..." } },
      { "redirect" : { "url" : "somewhere_else" } }

Some more details about the above Rule:

  • Rules Event: Drupal is initializing.
  • Rules Conditions:
    • the user should NOT be anonymous, AND
    • either (or both) of these conditions must be true:
    • the path is node/123 (assuming your homepage is a node with nid=8, adapt to fit your case, or omit this condition if the next condition is sufficient for your case).
    • the url contains the text something (adapt to fit your case, or omit this condition if the previous condition is sufficient for your case). Instead of using Comparison operation contains you could also use starts with, ends with or even a regular expression.
  • Rules Actions:
    • Show an appropriate message (adapt to fit your needs, or just omit it if you don't want such message at all, I like it for debugging purposes ...).
    • Perform a redirect to somewhere_else (adapt to fit your needs).

If you have the Rules UI enabled, you should be able to import the above rule in your own site. Then adapt it to fits your needs and you should be good to go.

Easy, no?

  • Thanks for your reply. I ll try your solution. But what should I insert to path since I want to be triggered in homepage? There is no path only the domain of the site. Commented Nov 9, 2017 at 11:29
  • @DimitriosMarkopoulos check my updated answer, and let me know if it helped. Commented Nov 9, 2017 at 12:07
  • Your way helped me a lot. The change I made was to insert custom php code return drupal_is_front_page(); instead of path and url because my frontpage is with panels and not a node. thanks again! Commented Nov 9, 2017 at 13:01
  • @DimitriosMarkopoulos merci for the feedback! May I say "What else did you expect"? BTW: never (repeat never) use custom PHP code when using Rules, because it requires the dangerous PHP filter to be enabled (and which is no longer in D8 core ...). In my experience, I have never had the need for any custom PHP code when using Rules. Next (Rules?) question? Commented Nov 9, 2017 at 13:18
  • thanks, I didnt know that php filter is dangerous. My issue was that I couldn't set a path because in front page there is no path, only the domain name (example.com e.g.). Is there a way to overcome this? Commented Nov 10, 2017 at 6:41

Your Answer

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

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