1

My users are only able to log in on the mysite.com/user page (I don't use any of the login blocks). How can I redirect those users to their location "two pages ago"? For example, they might visit the about us page, then click login (taking them to the /user page). After they complete their login, I would like for them to be redirected back to the about us page.

I currently have it set to redirect to the previous page after login, but that will always be the "user" page, which is not particularly useful in this instance.

Thanks!

2 Answers 2

1

Append

?destination=[PATH]

to your login link.

You can do this with the Menu Token Module

3
  • So it would look like this? mysite.com/user?destination=[PATH]... Or do I need to add a path where it says "[PATH]" in your example? If the latter is true, then that will not work as that would create a single redirect destination and I need the redirect destination to be "two pages ago".
    – hockey2112
    Aug 7, 2014 at 22:06
  • well you'd take the current url alias and apply that to the login link. I guess you'd have to also disable the automatic redirection to user page. You might try that. If that doesn't work you could try making use of a session variable.
    – SDMulroy
    Aug 7, 2014 at 22:09
  • also check this page drupal.org/node/683696
    – SDMulroy
    Aug 7, 2014 at 22:13
0

If you have put the user/login in a menu you can you this theme function in your template.php file to override the links to add the destination parameter, here is a sample code.

function yourthemename_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  // Add destination query parameter for login, logout and register menus
  if (in_array($element['#href'], array('user/login', 'user/register'))) {
    $element['#localized_options']['query'] = array('destination' => current_path());
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

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.