简体   繁体   中英

How to make absolute redirect in Drupal?

From my custom module in Drupal 7 I want to make the redirect.

So, inside a function, I have:

$my_calculated_path = $base_url . '/dashboard/test/deliveries;
drupal_goto($my_calculated_path);

If I print the variable $my_calculated_path I have the full url:

www.mydomain.com/dashboard/test/deliveries

and it is correct.

The problem is the drupal_goto($my_calculated_path) trigger the hook menu:

/dashboard/test

and not the menu:

/dashboard/test/deliveries

What is the problem?

Use 'external' option for external redirections:

drupal_goto($url, array('external' => TRUE));

See: drupal_goto() and url()

Normally drupal_goto() does not allow absolute paths because this could represent a vulnerability.

Try it this way:

drupal_goto('dashboard/test/deliveries/', drupal_get_destination());

The drupal_get_destination() function will create the proper URL for you.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM