从 Drupal 站点内重定向到新页面 [英] Redirect to a new page from within a Drupal site

查看:23
本文介绍了从 Drupal 站点内重定向到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个 Drupal 站点,我们想要设置一个重定向到外部站点的特殊 URL.换句话说,如果 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆