Making Sure Your Redirects Work as Expected

Published August 16, 2009

Whenever you need to write a custom module that involves redirection using the drupal_goto() function, things can always get tricky - especially if there are other forces at work. One such force might be the "destination" variable that sometimes gets passed around in the URL querystring when the user is attempting to access content that requires authentication.

I recently ran across the situation where the "destination" querystring variable was interfering with where I was attempting to redirect the user to. Luckily, there was a simple solution - I just "unset" the "destination" variable right before I redirected the user:


unset($_REQUEST['destination']);
drupal_goto('somewhere_completely_different');

Using this method, I ensure that the redirect was "clean" and there wasn't any possibility of any misdirection.

Comments

Mike, you told me to try the goto function to redirect to a view page, and it just wouldn't work. But I could tell it was not returing to after the goto call, so I knew something was fishy. Adding the unset did the trick!

Submitted by Guest (not verified) on Sun, 07/11/2010 - 20:49

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA