Drupal 7 / 8: Lightweight set / exchange domain specific front page (e.g. for landingpages)

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:

  1. /*
  2. * Set a different frontpage for the standalone landingpage: <a href="https://www.my-landingpage-example123.com<br />
  3. *" title="https://www.my-landingpage-example123.com<br />
  4. *">https://www.my-landingpage-example123.com<br />
  5. *</a> See https://julian.pustkuchen.com/node/794
  6. */
  7. if($_SERVER['HTTP_HOST'] == 'www.my-landingpage-example123.com'){
  8.   $conf['site_frontpage'] = 'node/14';
  9.   // Make this switch work with Caching enabled:
  10.   drupal_page_is_cacheable(FALSE);
  11. }

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?

  1. /*
  2. * Set a different frontpage for the standalone landingpage: <a href="https://www.my-landingpage-example123.com<br />
  3. *" title="https://www.my-landingpage-example123.com<br />
  4. *">https://www.my-landingpage-example123.com<br />
  5. *</a> See https://julian.pustkuchen.com/node/794
  6. */
  7. if($_SERVER['HTTP_HOST'] == 'www.my-landingpage-example123.com'){
  8.   // NOT WORKING CODE - PLEASE HELP TO FIND A GOOD SOLUTION:
  9.   // This leads to an exception and caching problems when calling the landingpage domain:
  10.   $config['system.site']['page']['front'] = '/node/44';
  11.  
  12.   // This is NOT Possible at this early point:
  13.   //\Drupal::service('page_cache_kill_switch')->trigger();
  14. }

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?

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen