Would you like to create a Landingpage for a specific topic in Drupal 7 / 8 on a separate landingpage domain (https://www.my-landingpage-example123.com/) as specific frontpage without using complex modules like Domain Access or multisite?
Then here's the lighweight way to go for you!
What's the situation and plan?
We're running a Drupal 7 or Drupal 8 Website on e.g. https://www.example.com
We'd like to create a content aka "node" on this installation easily, for example from a separate content type "Standalone landingpage" or something like that
We want to present that content aka "node" as (standalone) front page / landingpage on e.g. https://www.my-landingpage-example123.com
We don't want any heavy weight modules or multisite installations
How can we achieve that?
Exchange default front page based on the domain / host:
Drupal 7
Add the following snippet to the end of your settings.php and edit the domain names and node ID:
/*
* Set a different frontpage for the standalone landingpage: https://www.my-landingpage-example123.com
* See https://julian.pustkuchen.com/node/794
*/
if($_SERVER['HTTP_HOST'] == 'www.my-landingpage-example123.com'){
$conf['site_frontpage'] = 'node/14';
// Make this switch work with Caching enabled:
drupal_page_is_cacheable(FALSE);
}
?>
Drupal 8
Sadly this simple way does NOT work for Drupal 8 yet. This was my starting point but it seems to be more complicated here. Perhaps someone has a lightweight solution?
/*
* Set a different frontpage for the standalone landingpage: https://www.my-landingpage-example123.com
* See https://julian.pustkuchen.com/node/794
*/
if($_SERVER['HTTP_HOST'] == 'www.my-landingpage-example123.com'){
// NOT WORKING CODE - PLEASE HELP TO FIND A GOOD SOLUTION:
// This leads to an exception and caching problems when calling the landingpage domain:
$config['system.site']['page']['front'] = '/node/44';
// This is NOT Possible at this early point:
//\Drupal::service('page_cache_kill_switch')->trigger();
}
?>
Remove default page elements for standalone landingpages
Optionally on a standalone landingpage you may want to hide regions, move blocks or make other specific modifications to your theme.
These strategies may help you:
- Create a subtheme and inherit everything (but your changes). This also gives you separate control over your blocks for the subtheme and allows for specific overrides
- Create a separate content type e.g. "Standalone landingpage" and override its page.tpl / page.html.twig. Also you may want to exclude it from your main website sitemap.xml
Any better ideas, extensions or alternatives?
If you have any ideas for alternative or better solutions, please feel free to leave a comment. This is just one possible example of how to solve that situation and depends on multiple criteria.
For Drupal 8 we might need to create a custom module for that to disable caching and exchange the front page accordingly?