Drupal 6: Redirect Users to your Frontpage/Startpage/node after they logged in

In Drupal 6 this can be done with core modules like this:

  1. enable Trigger module
  2. add an action
  3. add advanced action at the bottom and choose “Redirect to URL”
  4. use description regardless of how you will use it but rather describing what this action does; e.g. “redirect to start node”
  5. as URL apply “node” (without the quotation marks). Instead of node you can redirect to any url you like. See my screenshot for how it could look.
  6. set-up the appropriate trigger
  7. from the drop-down list at “Trigger: After a user has logged in” select your new action from just now
  8. log out and back in again to test it

Note: In the links provided you need to change “your-domain-path-to-drupal” with your actual domain name to become something like http://example.com/admin. Or navigate as usual if you now where to find the settings pages in Drupal 6. If you happen to have clean urls disabled you might know already that you need to prefix the admin path (as every other path) by “?q=” so it all together looks like this: http://example.com/?q=admin. This, however, doesn’t concern the node parameter where you redirect to. That’s always an internal relative path without the leading slash; or some full url of corse.

Update 05/2009: If you want a simple module to do that for you useLogin Destination. To redirect user/1 to /admin and site users “back” to the page they logged in from the following PHP snippet should work for Drupal 6 (not tested, feedback welcome!):

global $user;
  if ($user->uid == 1) {
    // Redirect the Administrator
    return 'admin';
  } else {
    return ($_REQUEST['q']);
  }

Resources

94 Comments

  1. LEternity said,

    Thursday, 11th Mar 2010 at 04:23

    Hi,

    I’m really struggling with this one. Drupal just absolutely ignores my trigger. It also doesn’t react to any hook_user() implementation or to the Login Destination module. I’ve tried everything. Yet, Drupal keeps redirecting me to my home page everytime I log in. I’m using the user login block.

    Please help or I will have to pull the rest of my already grey hair because of this bug.

  2. Alon said,

    Wednesday, 10th Feb 2010 at 16:20

    Thanks alot, I was looking for this for a while.

    =]

  3. Dani said,

    Wednesday, 7th Oct 2009 at 13:49

    Thanks for the tip! Very useful!

  4. mike said,

    Monday, 4th May 2009 at 16:25

    when users log out of my site, they see a white page, nothing else. im a newbee, but i thought by default they should be redirected to the front page??? i have tried to set a redirect action on user log out, but the redirect option comes up everwhere except in the log out trigger. any help would be appreciated.

    • sysblog said,

      Monday, 4th May 2009 at 17:56

      mike, that’s the “white screen of death” I’m afraid, saying there is something wrong with your installation of drupal. You might want to search for “white screen of death drupal log out” with your favorite search engine of choice. Good luck!

  5. You said,

    Friday, 1st May 2009 at 17:09

    Is there a way to STOP redirection upon login?

    With drupal 6.11, upon login users are directed away from their current page to the profile page. I liked the old behaviour of staying on the same page.

  6. a_c_m said,

    Thursday, 26th Mar 2009 at 16:30

    Handy tip!

    Thanks for sharing.

  7. Asak said,

    Friday, 27th Feb 2009 at 14:50

    Would you happen to know how to use triggers/actions/rules to redirect after FIRST login only? I’m trying to figure this out…

    Thanks!

  8. sysblog said,

    Sunday, 22nd Feb 2009 at 22:22

    Great to hear I could be of help and thanks, size, for sharing your knowledge with everyone!

    Have fun with Drupal!

  9. size said,

    Saturday, 21st Feb 2009 at 01:09

    ok let me answer my own question…

    1. Apply the trigger for when a user logs in and not when the user registers (as Gavin suggested it prevents the e-mail from being sent and in my case didn’t login the new user)

    2. Set the to trigger point to http://whatsmysize.com/clothing/user/

    Job done – time for bed

    Thanks so much for posting this in the first place…

  10. size said,

    Saturday, 21st Feb 2009 at 00:31

    Thanks so much this worked a treat (as I looked for about 3 hours before I found you I am delighted)

    I am keen for a user who registers to redirect to their own profile page – as a newbie could anyone point me in the right direction ?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: