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 ?

3 Answers 3

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

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 and acknowledge you have read our privacy policy.

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