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

21 Comments

  1. Monday, 16th Feb 2009 at 19:53

    [...] can also use the core trigger module instead but you will have much more features with Rules like creating different workflows (the Rules module [...]

  2. Sebastián said,

    Wednesday, 4th Feb 2009 at 23:38

    Works like a charm! Thanks!

  3. sysblog said,

    Saturday, 6th Dec 2008 at 16:55

    Thanks for your comment, Gavin. Please consider reporting this bug so people who know there stuff can fix it and that way you help the community! Thanks.

  4. Gavin Doolan said,

    Friday, 5th Dec 2008 at 11:55

    I have another problem with this method. Setting up a trigger to redirect a user after they register causes the registration email to never be sent!

    Obviously this means that new users cannot login to the site and would need to be savvy enough to request a new password – which they will then receive the email.

    I tested my email settings over and over thinking this was the problem, but it turns out its this module.

  5. sysblog said,

    Tuesday, 16th Sep 2008 at 11:48

    Thanks for sharing! I wasn’t aware of this issue even though I looked into the issue queue yesterday. I guess this really is a bug and should be filed as such.

  6. mark said,

    Tuesday, 16th Sep 2008 at 00:43

    Here’s the problem. Above advice does not work if user logs in using login block. See:

    http://drupal.org/node/294439

  7. sysblog said,

    Monday, 15th Sep 2008 at 22:44

    “promoted to front page” has nothing to do with it. That only says this node is listed on the front page, i.e. what http://example.com shows.

    Also giving the full URL is not useful if it’s not only for testing. It should work with relative paths, too.

    Have you tried “node“, i.e. only the word without quotation marks, in the url field (see my screen shot I added above)? Also, what is the complete path, i.e. everything from the first single slash after the top-level domain, that your browser shows in the address bar? I don’t know if it could work but you might want to try “front” in cornered brackets, those as in HTML tags, again without quotation marks. (Unfortunately wordpress wouldn’t let me use them as it thinks it’s a HTML tag).

    Good luck.

  8. mark said,

    Monday, 15th Sep 2008 at 20:47

    Thanks for reply. Ok, now I’m really scratching my head. Yeah, I though it looked like it’s ’sort of’ working too. I just did a *fresh* install of drupal 6.4. Made 2 pages: node/1 and node/2. node/1 promoted to front page. Created action Description: “redirect to page 2″ URL: “node/2″ (also tried full http url). Set up trigger at admin/build/trigger/user in “Trigger: After a user has logged in” section to use my action. Logged out. Logged back in. Was redirected to ‘node’ not ‘node/2′ as expected. Took the ‘promote for front page’ off node/1 and still no redirection to node/2 after login. What are we doing differently?

  9. sysblog said,

    Monday, 15th Sep 2008 at 09:12

    It sounds as if the redirection might actually work since as far as I remember the “registration email link” is a one-time-login token. So you actually log in just by using this link but it only works once (this is why you don’t get your new password page). Strange, though, that it wouldn’t work on normal logins (I assume you do that by using example.com/user page). Would you care to share more details of what you did? For example have you tried another destination just to test? What’s the exact string you entered as the destination?

    I just tested it on a couple of installations I have and it still works with Drupal 6.4.

  10. mark said,

    Monday, 15th Sep 2008 at 08:11

    Hmmm…. seems like a darn cool module, but didn’t work for me. The only time it redirected was when I clicked on the link for an *initial* login – right after registering a new user and clicking on the link provided in the email where it’s supposed to take me to page to enter a new password. Instead of getting the new password page, I got redirected what I’d set up for general redirection after login. Any other time I login it’s just as before.

    /scratching-head/


Post a Comment