How to create a custom front page redirect for anonymous user?

1.5k views Asked by At

I have a web site at what-i.com that uses Drupal Commons profile. I have created a custom theme called 'whati' and placed it in /sites/all/themes folder. My page-front.tpl.php is supposed to drive my front page.

It has an if-else statements for 2 scenarios: logged in and non-logged in users. For logged in users, everything works great: upon logging in, the user sees my custom front page. For non logged (anonymous) users, it always forwards them to http://what-i.com/user?destination=home. I don't know how to override that redirect: it does not pick up on the if statement in my page-front.tpl.php, I tried using frontpage module with no success, and I also tried to change the front page settings under Site Information to no avail.

Can anybody help me to resolve this issue: that is, instead of being redirected to user?destination=home, I want my anonymous users to see a custom front page I created.

1

There are 1 answers

3
Kevin On

You can do this from a TPL file or a module init().

From a x.tpl.php:

if (drupal_is_frontpage()) {
   global $user;
   if ($user->uid == 0) {
       drupal_goto('some page');
   }
 }

From a module:

mymodule_init() {
   global $user;
   if ($user->uid == 0 && drupal_is_frontpage()) {
      drupal_goto('some page');
   }
}