Right now I have a redirect in my code:


Per the documentation drupal_goto defaults to a 302 redirect. I want a 301.

However, when I put in:

drupal_goto($path, $http_response_code = 302);

It gives me an error:

Argument 2 passed to drupal_goto() must be of the type array, integer given,

But if I try something like:

drupal_goto($path, array $options = array(), $http_response_code = 302);

...I get this error:

Unexpected '$options'

How can I properly change drupal_goto into a 301 redirect?

2 Answers 2


Looks like you're mistaking the function definition for an implementation example.

The function definition describes the arguments to use, but it's not a literal example of how to call it.

So when you want to use the drupal_goto() function, instead of this:

drupal_goto($path, array $options = array(), $http_response_code = 302);

It should look more like this:

drupal_goto($path, array(), 301);
drupal_goto($path = '', array $options = array(), $http_response_code = 302)

Initialize $option as empty array something like this

$options = array();
$path = <your path>;
drupal_goto($path, $option, 301);
  • so I need both lines one after the other?
    – YPCrumble
    Oct 22, 2015 at 20:53
  • it should be like this $options = array(); $path = <your path>; drupal_goto($path, $option, 301);
    – Shabir A.
    Oct 22, 2015 at 20:54

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.