Currently I'm using Drupal as my authentication system, and I would like to redirect user to our main site after login, according to an URL-passed parameter, for example user/login?redir=http://google.com. And yes I've found out there is a destination parameter however it doesn't work it the passed argument begins with http or somehow a non-Drupal path. Any ideas? hook_drupal_goto_alter is a hook I found might be helpful, but not sure how to implement it.

1 Answer 1


The issue with ?destination= is that it provides no mechanism for setting external => TRUE for the options in drupal_goto(), which Drupal needs to redirect to an off-site location.

I think the easiest way to get what you're looking for is to implement hook_form_alter() for the user login form, save the URL parameter if it's available, and then manually redirect in the submit handler.

Something like this:

function MYMODULE_form_user_login_alter(&$form, &$form_state, $form_id) {
  if (isset($_GET['redir'])) {
    $form['redir'] = array(
      '#type' => 'value',
      '#value' => $_GET['redir']

    $form['#submit'][] = 'MYMODULE_user_login_redirect';

function MYMODULE_user_login_redirect(&$form, &$form_state) {
  $form_state['redirect'] = array($form_state['values']['redir'], array('external' => TRUE));
  • you should know better. Use $form_state['redirect']
    – googletorp
    Commented Aug 14, 2012 at 4:17
  • @googletorp Not sure what happened there :/ In my defence that was quite near my birthday so I may have been drunk ;)
    – Clive
    Commented Aug 14, 2012 at 7:43

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.