I want to redirect this the request for "homebox/1" to "homebox/1/[uid]" if a logged in user tries to access it. I do not care about annonymous users at this point yet.
This is the code I put into the top page-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, do the *.tpl.php files get processed late in the request? In that case I am doing it rather inefficiently.
I know about the path redirect module(http://drupal.org/project/path%5Fredirect). I don't want to use that because I'd like to learn whether there are any Drupal API for redirecting and/or methods to catch and redirect the request right at the beginning of the processing chain.
Thanks Arul