2

I have some pages with urls like this:

http://example.com/landing/abcd
http://example.com/landing/efgh

as menu items: $items['landing/%'] = array( 'title' => 'Landing page', 'description' => 'Landing page', 'page callback' => 'mymodule_landing_display', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, );

Now i want to use them as the home page of the domains:

http://abcd.com/
http://efgh.com/

I don't want to use a simple redirect.

What is the best way to do it ?

2

Use Domain Access: https://www.drupal.org/project/domain

Core Drupal + Domain Access can do this, you don't need any code or custom modules. Your Drupal can load different content on each configured domain name.

  1. Point all domains in Apache/Nginx at the same Drupal install directory.
  2. Install Drupal using your primary domain.
  3. Create your Landing Page nodes using the default Page Content Type.
  4. Install Domain Access.
  5. Add a new Domain at: http://example.com/admin/structure/domain/create
  6. Edit the Domain settings at: http://example.com/admin/structure/domain/view/:id/config and specify the Site frontpage.
  7. Done.

If you want it in code, you can export the entire configuration with the Features module: https://www.drupal.org/project/features

1

If you actually just want to use these pages as one-pager / landing-pages (as the url 'landing' suggests) it could also be done by adjusting your domain settings for abcd.com and efgh.com.

At least with my webhost I can adjust where a domain would look for its content. Setting the 'home' path to /landing/abcd (or actually seting the 'A-entry' of the dns registry accordingly) would do the trick on the server I'm working on – at least when all three domains share the same webspace.

So you might also consider asking your question over at stackoverflow.com or webmasters.stackexchange.com since it could be a more technical question.

0

Typically this would handled by a multi-site setup (not a module with custom menu handlers) if you're looking for Drupal to serve abcd.com & efgh.com as well as example.com.

If that's not an option for you (e.g. you're looking to make some quick splash pages for advertising), then the other option is to create a new webroot for http://abcd.com/ & http://efgh.com/ & add an index.html with an 100% iframe in the source

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>ABCD</title>
    </head>
    <body>
            <iframe width="100%" height="100%" src="http://example.com/landing/abcd" />
    </body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>ABCD</title>
    </head>
    <body>
            <iframe width="100%" height="100%" src="http://example.com/landing/efgh" />
    </body>
</html>
  • I am looking for a clean way to do it. Something like variable_set('site_frontpage', 'mylanding'); but without writing always in the DB. – user1014351 Apr 8 '15 at 16:49
  • Then you're looking at mulit-site setup. You should checkout this answer that discusses such a solution with Ctools Page Manager. – Shawn Conn Apr 8 '15 at 17:33
0

If you need to accomplish this with a custom module instead of following Shawn Conn's suggestion of a multisite setup, you can do something along the lines of adding a menu handler whose callback will examine the http host that the request came in on and pass that along to your mymodule_landing_display function. Then set this new menu item's path to site_frontpage using the "Default front page" setting on admin/config/system/site-information. Something like this:

Item for hook_menu:

$items['landing'] = array(
  'title' => 'Landing page chooser',
  'description' => 'Landing page chooser',
  'page callback' => 'mymodule_landing_display_chooser',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
);

Callback function:

function mymodule_landing_display_chooser() {
  $choice = str_replace('.com', '', $_SERVER['HTTP_HOST']);
  if($choice == 'example') {
    // If this is the main 'example.com' domain, use default front-page content, or change this to whatever content you want to deliver for your main domain
    return node_page_default();
  }
  else {
    return mymodule_landing_display($choice);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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