2

I have to change dynamically the homepage according to the server HTTP_HOST. I've tried to update $_GET['q'] inside the settings.php. It works but, the internal drupal function drupal_is_frontpage() compares with the drupal_get_variable('site_frontpage'). A suggestion ? Thanks.

3 Answers 3

2

Try either the domain access or subdomain module.

Update:

As a poor-man's solution, in settings.php, you could try the following:

if ($server['HTTP_HOST'] == 'foo.com'){
  $conf['site_frontpage'] = 'node/XXX';
} elseif ($server['HTTP_HOST'] == 'bar.com') {
  $conf['site_frontpage'] = 'node/YYY';
}

Thanks @Chance G for a good idea.

2
  • Thanks for the anwsers @greg_1_anderson and @Chance G. In fact, the variable $conf is not defined in settings.php. I've move this switch after bootstrap call, in index.php (I will move this in a module), but it works correctly. Finnaly, updating $_GET['q'] and $conf['site_frontpage'] solve my problem. Thanks
    – Tgahnsell
    Oct 22, 2012 at 7:47
  • In fact, this code must be inserted after menu_execute_active_handler().
    – Tgahnsell
    Oct 22, 2012 at 8:07
0

In your settings file or theme preprocess file you could add something like the following using the variable_set function:

if ($server['HTTP_HOST'] == 'foo.com'){
  variable_set('site_frontpage', 'node/XXX');
} elseif ($server['HTTP_HOST'] == 'bar.com') {
  variable_set('site_frontpage', 'node/YYY');
}
1
  • 2
    This is a good idea, but a bad implementation; variable_set will affect all visitors to the site. If you have multiple page requests all at the same time, some users will get the frontpage set for other users. Make the change to $conf['site_frontpage'] in settings.php and it should work right, though. Oct 19, 2012 at 16:55
0

variable_set() is a really really bad idea because it touches the Database everytime. Bad for performance, logically, etc... Simply don't do that ;)

But I extended the solution from @greg_1_anderson a bit by also ensuring the front page is not being delievery from cache, see my blog post: https://julian.pustkuchen.com/node/794

I think that's a good solution for Drupal 7. For Drupal 8 I didn't yet find a simple solution, perhaps someone has an idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.