Drupal login redirection

By Erik, 12 December, 2011

One handy trick I've found is that when you're visiting a Drupal page and you notice that you're not logged in, you can simply add user?destination= into the URL right after the root of your Drupal site and keep the path. This means that

http://eporama.com/ramblings

becomes

http://eporama.com/user?destination=ramblings

Then when you log in, you're brought back to the page you were viewing with no fuss.

I do this often enough that I decided to make it a bookmarklet.

javascript: function adduser() {
  var d = document,
  b = d.body,
  l = d.location;
  try {
    if (!b) throw (0);
    d.location.href = 'user?destination=' + l.pathname.substring(1);
  } catch(e) {
    alert('please wait');
  }
}
adduser();
void(0);

This seems to work well in Firefox, Chrome and Safari on the Mac... and here's the condensed version ready to be copied into a bookmark.

javascript: function adduser() {var d=document,b=d.body,l=d.location;try {if (!b) throw (0);d.location.href='/user?destination='+l.pathname.substring(1);} catch(e) {alert('please wait');}}adduser();void(0);