Tutorial 1: On login redirect to the user's account page

Last modified: October 4, 2009 - 20:28

The first short tutorial will show, how rules can be used, to configure a simple page redirection after a user has logged in.

As an alternative, one can just import the ready rule from here.

Requirements

  • Drupal 6.x
  • Trigger core module must be activated under admin/build/modules

Optional

  • Token contributed module if you want to use tokenized URL. Make sure that the Token sub-module Token actions is activated.

Steps

  1. We are now going to create an action. To do so go to Actions settings page under admin/settings/actions
    Scroll down the page to find the section Make a new advanced action available.
    Click on Choose an advanced action drop down menu.
    Choose Redirect to URL.... Note that if you want to use a tokenized URL then choose Redirect to a tokenized URL...
    Click on Create button.

    A new window opens Configure an advanced action
    Under Description: you should read Redirect to URL. This is optional but to better identify the precise action taking place you should change the Description field. This description will be displayed in modules such as the trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Redirect to the user's account page" rather than simply "Redirect to URL").
    Under URL: type in the URL you want the user to be redirect to after logging in. In my case for this tutorial I want the user to be redirected to the user's account page so I type in

    user

    More URL: examples

    • <front> will redirect user to your site default front page. As defined under admin/settings/site-information.
    • user/[user-id]/track will redirect user to user's Track page. To read more about tokenized actions expend the Placeholder tokens section located at the bottom of Configure an advanced action page. Note that you must install Token contributed module if you want to use tokenized URL. Plus you must activate the Token sub-module Token actions.

    Click on Submit button.
    You have successfully created an action. You now have a new line added to Actions available to Drupal: section.

  2. We are now going to create a trigger. To do so go to admin/build/trigger
    Click on appropriate tab located at the top of this page. In this tutorial I click on Users tab.
    Scroll down the page to find Trigger: After a user has logged in.
    Click on Choose an action drop down menu.
    Choose Redirect to URL action or choose the name you gave to your action.
    Click on Assign button.
    You have successfully created a trigger. Your action is now display under Trigger: After a user has logged in > Name.
    That's all. To test log-out and log-in. You'll be redirected.

note the token requirement!

pritishjacob - January 20, 2009 - 15:21

FYI following this tutorial, you'll log in and get a page not found error if you don't install the token module. The url trailer might end "/user/[account%3Auid]" upon logging in without enabling that module.

Redirect to front page

tryitonce - April 2, 2009 - 11:18

I tried to use this tutorial to change the login redirection from the user account (default in my Drupal installation) to the front page.

This tutorial din't work for me at all. As with so many instructions here the people writing them never take the time to put the correct terms and links in to make life easy and to avoid confusion.

Anyway, may be this tutorial works and I am on the wrong "garden path". In any case this is what I did to get users on login to the front page.

1. ..../admin/settings/actions (Actions settings page)
Go to the bottom and open the drop down menu to the left of [create] and choose Redirect to URL press [create].
2. A new window opens - "Configure an advanced action"
Here you should read -
Description:
Redirect to URL
In the line below add the page link where your users should arrive at after logging in. In my case I choose <front>.
URL:
<front>
Press [Save] and now you should have a new line added to "Actions available to Drupal:"
system ....... Redirect to URL ..... configure .... delete
3. Next step - go to Triggers. You can click on it above in the explanation text or use ..../admin/build/trigger/node.
Now choose the user tab or .../admin/build/trigger/user.
Go down to Trigger: After a user has logged in.
From the drop down box choose "Redirect to URL" and press [Assign].

Done!!! [I hope ;-) ]

If you are redirecting to another page you might need to experiment with the link code along the lines of .../content/user-start-here-page.

Good luck

This really works thanks! I

dropchew - April 20, 2009 - 13:59

This really works thanks!

I had no luck with rules redirecting to frontpage but the action and trigger combo really solve it.

Enable the Trigger Module..

snohio - May 1, 2009 - 15:42

I know that this is probably idiotic, but it took me too long to realize that I had to enable the Trigger Module. I thought I would drop a note here to save other people like me 20 minutes.

idiotic but useful, this

castawaybcn - May 18, 2009 - 11:42

idiotic but useful, this simple tip saved me a lot of headaches. Thanks!!

Thanks you.

_double - September 14, 2009 - 23:17

Thanks you.

Thanks snohio

Onopoc - October 4, 2009 - 18:55

Thanks for your comment snohio. I have updated the tutorial by adding a 'Requirements' section.

It works ..... but I have a question

niemag - May 18, 2009 - 12:19

Your comment saved my day today. Great thanks! :-)

BUT... I have two sub-sites - each of them I would like to redirect to its own front page after logging in. With one sub-site your procedure works smoothly, but the second sub-site is always redirected to /admin.

Moreover I cannot force neither of them to redirect to any other URL (e.g. http://drupal.org, or node/2, or ... ... ... ...). It seems that there is only one direction for each sub-site (somewhere written) and nothing can chage it.

Is there any problem with my configuration? I am quite new in Drupal world... Maybe any module I need to install or switch on.

I appreciate any help.

For redirecting to the front

guysaban - May 26, 2009 - 07:47

For redirecting to the front page just follow the tutorial at the top of the page and leave the redirect field empty. Explanation, since the redirect is relative to the sites Base URL (domain) leaving the redirect field empty will redirect to the base url. Anything placed in the redirect field will just be appended to the base URL.

Thanks tryitonce

Onopoc - October 4, 2009 - 20:19

Thanks tryitonce. I re-wrote the tutorial base on you comment.

wrong module

jsulmar - October 5, 2009 - 15:54

Hi Onopoc,
The original tutorial worked for me using the Rules module. I suggest you place your re-write into documentation for the trigger module, NOT the rules module. I think a lot of people are confused that trigger and rules modules are alternative, distinct implementations.

trigger vs. rules module

jsulmar - October 5, 2009 - 15:47

Note that the trigger and rules modules are separate, alternative solutions to the task of "triggering actions". It appears that you were unable to get the rules tutorial to work, so you developed your own similar procedure using the trigger module.

I'm also still on the learning curve on this, but I think the rules module claims to be a more versatile and powerful alternative to the trigger module. The documentation doesn't make it completely clear, but I think one should turn off the trigger module in order to use rules.

Install latest development version of Token module

ozwebguru - April 21, 2009 - 14:11

You need to install latest development version for token replacements to work. Any version after 27-AUG-2008. http://groups.drupal.org/node/10270/rules-modules
Also see FAQ here http://groups.drupal.org/node/15542

Can't get either walkthrough to work...

clintcar - September 23, 2009 - 13:43

I know I'm a newb, but I have followed the main instructions and the one in the thread exactly and cannot get the redirect to actually work. Assuming there is no step missing in either walkthrough, has anyone else had a problem getting this to work? I'm so excited about learning and using rules, but hitting a roadblock right away, am I the only one?

EDIT

I was able to setup an exact same rule on users logging out. So my problem seems to be specific to a rule when a user logs in. Leaves me even more confused onto why... but at least I'm getting rules to work. Anyone have an explanation for this?

redirect URL NOT work but display message works???

hosais - October 24, 2009 - 18:39

Hi,

I set an action (redirect URL[internal or external links) to the Trigger (After a user has logged in). When a user login, it always goes to the orginal page (the page when it is logout status).

I tried to set another action (display message) to the same trigger (after a user has logged in). It shows the message.

Can anyone tells me why this URL redirect does not work?

Note: I tried both action/trigger or rules module. The results are the same.

Thanks.

hosais.

I've the same problem: the

FiNeX - October 29, 2009 - 11:07

I've the same problem: the debug message is displayed, but it shows the destination token, not the token value, and it doesn't do the redirect.

 
 

Drupal is a registered trademark of Dries Buytaert.