Issue #1954462: Query string is not kept during authentication

D5 port for patches in https://drupal.org/node/1954462.