从Drupal站点重定向到新页面 [英] Redirect to a new page from within a Drupal site
问题描述
我正在使用Drupal网站,我们要设置一个重定向到外部网站的特殊网址。换句话说,如果 http://www.mysite.com 是我们的Drupal网站,我们希望拥有 http://www.mysite.com/external 重定向到外部网站。
I'm working with a Drupal site, and we want to set up a special URL that redirects to an external site. In other words, if http://www.mysite.com is our Drupal site, we want to have http://www.mysite.com/external redirect to the external site.
我对Drupal的经验很少,不知道如何设置。任何帮助不胜感激!
I have very little experience with Drupal and have no idea how to set this up. Any help is appreciated!
推荐答案
如果您想要的是将用户重定向到同一个网站,当他们遵循将他们带到 http://www.example.com/external ,然后您可以实现 hook_menu()使用与以下代码相似的代码:
If all you want is to redirect the users to the same site, when they follow a link that takes them to http://www.example.com/external, then you can implement hook_menu() using code similar to the following one:
function mymodule_menu() {
$items = array();
$items['external'] = array(
'title' => 'Redirect',
'page callback' => 'mymodule_redirect',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function mymodule_redirect() {
drupal_goto($url, array('external' => TRUE));
}
如果用户被重定向的URL取决于在URL,那么你可以使用类似于以下代码:
If the URL to which the users are redirected depends from a value passed in the URL, then you can use code similar to the following one:
function mymodule_menu() {
$items = array();
$items['external/%'] = array(
'title' => 'Redirect',
'page callback' => 'mymodule_redirect',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function mymodule_redirect($id) {
// Calculate $url basing on the value of $id.
drupal_goto($url, array('external' => TRUE));
}
这篇关于从Drupal站点重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!