How to set up a Magento Multistore using multiple domains

in Magento Tags: DNSMagentoNginx

Instead of setting up a Magento multistore using subfolders, it’s also possible to set up your multistore using multiple domains. These domains connect to different storefronts on your Magento installation.

Point your domain(s) to your Hypernode

There are two ways to point the DNS to your Hypernode:

  • Let Byte manage your DNS
  • Use CNAME records to point your DNS

The first option is the preferred options. Both ways are explained in the article DNS settings Hypernode.

When Byte manages your domains, read the article Link your domain to your Hypernode to complete the set-up.

Check your storefronts

To correctly install your multistore, you’ll need to know what storefronts you have. There are two ways to check:

Via the Magento backend

Go to your Magento backend and navigate to System → Manage Stores. In the utmost right column (Store View Name), you’ll see a list of names of your storefronts.

Via Magerun

To check your storefronts via magerun, log on to your SSH server and type:

magerun sys:store:list

The command will show you a list of used storefronts.

Configure Nginx

Now you know what storefronts you have, you can edit your nginx config. Log on to your SSH server and navigate to: /data/web/nginx and open the file: http.magerunmaps. It will show you the following:

## Use this file to connect domainnames with storefronts.
## By default, these variables are unset and logic in Magento's
## index.php will take over.
##
## Use this file if you do not want to hack index.php. Follow the
## commented examples.

# should be named runcode :)
map $http_host $storecode {
 hostnames;
 default mydefault_storecode;
   .yourshopA.com shop_a;
   .yourshopB.com shop_b;
}

# should be named runtype :)
map $http_host $storetype {
 hostnames;# default store;
   .yourshopA.com website;
   .yourshopB.com store;
}

To link the storefronts to your domains change the lines:

  .yourshopA.com shop_a;
  .yourshopB.com shop_b;

To the domains you are using in your Magento installation

Generating your magerun mappings

If you need some help creating the http.magerunmaps file, you can use n98-magerun. We created a plugin that generates a http.magerunmaps based on your current storefront configuration:

n98-magwhypernode:maps-generate

Which will generate the following output:

app@abcd1234-example-magweb-do:~$ n98-magerun hypernode:maps-generate

map $host $storecode { hostnames; default deurdrangers; .example.net example_net; .example.be example_be; .example.com example_com; }

Don’t forget to remove the n98-magerun header from the output!

Additional information

0