Drupal api redirection

I want to redirect the request for "homebox / 1" to "homebox / 1 / [uid]" if the login user tries to access it. I am not interested in anonymous users at the moment.

This is the code I entered into the top-homebox.tpl.php:

if(!is_numeric(arg(2))){
global $user;
if($user->uid){
    if(count($_GET) > 1){
        $get = array();
        foreach($_GET as $k=>$v){
            if($k != 'q')
                $get[] = $k.'='.$v;
        }
        $get2 = '?'.implode('&',$get);
    }
    header("HTTP/1.1 301 Moved Permanently");
    header('location:/homebox/1/'.$user->uid.$get2);
}else{
    //redirect to error page
}
}

      

However, are the * .tpl.php files processed at the end of the request? In this case, I am doing it rather inefficiently.

I am aware of the path redirection module ( http://drupal.org/project/path_redirect ). I don't want to use this because I would like to know if there is any Drupal API for redirecting and / or methods to catch and redirect the request right at the beginning of the processing chain.

Thanks Arul

+2


source to share


1 answer


You may have had to use hook_menu_alter () , but it looks like the homebox_menu () function does not define an entry for homebox /

So, you just write your own hook_menu that matches homebox / and defines a callback and places your logic there.



You probably want to do drupal_goto () to do the redirection.

Well done for searching to remove this kind of logic from the template.

+8


source







All Articles