Home > Magento Tutorials > One Magento Installation on Multiple Domains

One Magento Installation on Multiple Domains

Posted on: 12th Jul 2010 By: Adam Moss 38 Comments

Plesk is a terrific control panel for multiple reasons – it allows complete administration for all of your websites that are hosted there. This includes the setup of SSL certificates, local database access, SSH access, the ability to switch domains off at the flick of a switch and much more. By much more I’m talking about ‘Domain Aliases’.

It has become an increasing requirement for me to have multiple domainsĀ  using the same Magento installation, and those multiple domains show different websites that are set up on that installation. I have domain1.co.uk which holds the Magento Installation, I also have domain2.co.uk which is a website on that Magento Installation. Okay so here’s how you do it…

1. Point DNS – Point the DNS A Record of domain2.co.uk to the IP address of domain1.co.uk.

2. Create Domain Alias – In Plesk, go to the domain overview area for your version of domain1.co.uk and click on ‘Domain Aliases’. Now click ‘Add Domain Alias’ and type in the name of the website (without the http://www part). So I type in domain2.co.uk.

Domain Alias

3. Create Website in Magento - In the Magento Admin area go to System > Manage Stores. Click on ‘Create Website’ and enter the name of the domain into Name field. You also need to enter a code to identify the website (you’ll need this later) – I just went with domain_2. As this isn’t my primary domain, I put the sort order as 2. You should also create an associative store and store view for this new website in the same way. Read my earlier post about websites/stores/store views for more information.

New Website

4. Change the Base URL - Go to System > Configuration > Web. Change the configuration scope (top left) to the secondary website (domain2.co.uk). You now need to change the secure and unsecure Base URL to the new domain, without forgetting to put the forward slash at the end of both.

Base URL

5. Update the .htaccess – Now that everything’s in place it’s simply a case of adding some code to the bottom of your main Magento .htaccess file so that Magento knows to load your new website when accessed from that domain. The code for my website domain2.co.uk would look like this:

SetEnvIf Host www\.domain2\.co.uk MAGE_RUN_CODE=domain_2
SetEnvIf Host www\.domain2\.co.uk MAGE_RUN_TYPE=website
SetEnvIf Host ^domain2\.co.uk MAGE_RUN_CODE=domain_2
SetEnvIf Host ^domain2\.co.uk MAGE_RUN_TYPE=website

You can see at the end of line 1 & line 3 that the website code I defined earlier as ‘domain_2′ has been appended accordingly. Save your .htaccess file and upload (or just save it if you’re doing it through Plesk). Without sounding like the official advocate of all that is Plesk, it really is a good way of configuring the server settings of your Magento site and can save you a lot of time and energy.

Thanks for reading the Magento Blog at E-commerce Web Design, I’d love to know how you all get on with creating your additional Magento URLs so please leave a comment and let me know.

38 Responses to “ One Magento Installation on Multiple Domains ”

  1. Zac
    #1 | 12th July 2010

    Hey Adam, I’m from Parallels and we really appreciate your great article. Could you email me (zcohn@parallels.com) and tell me a bit more about your experience with Parallels?

  2. Princy
    #2 | 14th July 2010

    Hi,
    I have a doubt .For the second domain i copied my main sites .htacess and index.php in a subfolder like
    main.com/sub.Then the main.com/sub works like a charm in server.But the issue is that i have to run the main.com/sub with domain name main2.com only.
    How can i make that possible.
    Waiting for a reply

    Thanks
    Princy

  3. Adam Moss
    #3 | 14th July 2010

    When you created the main.com/sub folder – did you create this as a website, or a store? You need to make sure that it is a website, you don’t need to have the subfolder anymore. If you follow my instructions on Plesk it will work.

    If you had created a store beforehand, create a new website which uses that store – and use that website code in the main.com .htaccess.

  4. PrincyJoy
    #4 | 15th July 2010

    Hi,
    Thanks for your reply.I already have a diffrent website running with different skin and even diff. customers .
    Bcs i was running that like mage::run(‘sub’,'website’).And was wrking well.
    My hosting provider is not providing me two domains in same account or even the IP pointing as you told.
    That is my issue .I did the things same as your documentation .Now i skipped the subfolder and following your docs.They are telling me like we should do this using magento http_host,
    Can you help me how can i do that way

    Thank you very much

    Princy Joy

  5. tuba
    #5 | 15th July 2010

    is it possible to use more than one domains hosted on different server.
    say, domain1.com where actual magento is installed
    now another domain domain2.com hosted on different server.

    what i want is, I want to run a site shop.domain2.com using same magento installed in domain1.com. how can i do that?

  6. Adam Moss
    #6 | 15th July 2010

    Tuba, you just need to point the DNS of domain2 to domain 1′s IP address and set up the domain alias. They can be registered on different servers, but they most be hosted on the same server for this method to work.

  7. Sebastian
    #7 | 18th December 2010

    I’m reading for hours on the web how to set this up and my mind was spinning..I’m reading you’re article and exactly 1 minute and 20 seconds later it’s working?! Adam Moss, my Hero for today…!

  8. Dave
    #8 | 8th January 2011

    Absolute legend! Simple and clear format – worked straight away = huge thank you!!

  9. Adam Moss
    #9 | 9th January 2011

    Dave & Sebastian – you’re both very welcome! :)

  10. Darren Sheffield
    #10 | 15th March 2011

    Hi

    Is it possible to set this up on subdomains ? as we test magento sites on a subdomian before going live.

    Thanks
    Darren

  11. Adam Moss
    #11 | 15th March 2011

    Yes there’s no reason why not.

  12. Darren Sheffield
    #12 | 15th March 2011

    When you set the domain alias it only seem to work on the root directory not the subdomain folders. I’ve added the modified .htaccess for a subdomain magento installation but no joy. Can you add something to the root to redirect to a subdomain ?

    Darren

  13. Adam Moss
    #13 | 17th March 2011

    Hi Darren, I’ve had a look and you may be right – you may have to use this other method: Multiple Domains with SSL

  14. R4mbert
    #14 | 7th April 2011

    Hi, u r the man!

    Thank u soooo much for this tutorial, simply, clear and working!
    I was burning my head around this feature to make it working and in a minute u solve everything.

    Thank u another time.

  15. Patrick
    #15 | 7th April 2011

    This is great info, just a question if we have for instance two domains how do we sort out the SSL certificate issue? As this way we only have a single dedicated IP address which would be the master domain and the domain aliases would hence share that IP address.

    Thank you for your time.

  16. Rose
    #16 | 7th July 2011

    I have 2 domains ( http://www.djgcreate.com/ZFS/ and http://www.zerofriction.com/ )
    the first domain works fine but I want to add the second one)
    I did your steps but I am getting 404 error: Page not found for both.

    why? what does that mean?
    the first domain was working fine before., I need help please ASAP.

  17. Adam Moss
    #17 | 7th July 2011

    Hi Rose, don’t worry this is down only to your store setup. If you set up your stores & websites in the wrong order it can result in a discrepancy somewhere. I assume that you’re currently unable to get into the admin due to the 404 problem?

    If so, you need to remove some data from the following database tables: core_store, core_store_group and core_website

    Be very careful while doing this though – if you want you can tell me the content of these 3 tables and I’ll tell you what rows can be safely removed.

    Once your site is back, you’ll have to add the new website again, make sure you create them in this order: 1) Website 2) Store 3) Store View

  18. wavi
    #18 | 7th July 2011

    Hi Adam,
    Thankyou for this “working” driveout ))

    all work fine with one exception :
    installation domain “site1.com” domain with plesk aliases “site2.com”

    when point at “www.site2.com” all is ok and site work.

    when point “site2.com” came visible .. “www.site1.com”

    any tips for adjust ?

  19. Prajosh
    #19 | 7th July 2011

    Hi Adam

    I tried to do this and I got the same issue with @Rose

    Now old and new url not working, getting 404 error.

    can u pls help to solve this issue ?

    Thanks
    Prajosh

  20. Adam Moss
    #20 | 7th July 2011

    Hi Prajosh, I’ve not heard of these errors occuring before which leads me to question if it’s possibly an issue with 1.5, in which case it would be the .htaccess code which is causing the problem. However I’m sure your problem is the same as Roses as I’ve seen this issue with 404 pages before when it comes to altering websites and stores. Can you follow what I suggested to Rose earlier and let me know the outcome?

  21. Rose
    #21 | 7th July 2011

    Thanks Adam for reply, as you said I have to be careful in the next step , so can you please send me your email or any account to chat live for the next step, please help help help. thanks

  22. Rose
    #22 | 7th July 2011

    I Have in core_store:
    0 admin 0 0 Admin 0 1
    1 default 1 1 Zero Friction 0 1

    in the core_store_group I have :
    0 0 Default 0 0
    1 1 Zero Friction 2 1

    and in the core_website I have :

    website_id code name sort_order default_group_id is_default
    0 admin Admin 0 0 0
    1 base Zero Friction 0 1 1
    2 zerofriction_code zerofriction.com 2 0 0

  23. Adam Moss
    #23 | 7th July 2011

    Ok Rose, it looks like you’ve got no store associated with the new website. I think the best method will be to remove the 2nd website data, then add it again in the admin.

    1) Leave core_store as it is
    2) Leave core_store_group s it is
    3) In core_website remove the final row with code (zerofriction_code)

    Please can you backup your database before making any of my suggested changes.

    Doing this should restore your main website, then go into the admin and set up your new website starting with the website, then store then store view.

  24. Rose
    #24 | 7th July 2011

    Thanks Adam for your help,

    what is your advice for me to setup the second domain to be open separately from the first one. because it is redirected to the main domain. since I have 2 installation and 2 databases.
    thanks

  25. Adam Moss
    #25 | 8th July 2011

    The fact that you have 2 installations defeats the object of this blog post entirely. Why can’t you just continue to have two separate Magento websites on 2 separate domains – the way you’ve got it isn’t ideal, but I don’t think there’s a problem.

  26. Prajosh
    #26 | 8th July 2011

    Hi Adam,

    Thanks for the reply.

    I have fixed the issue by adding store code in index.php as below.
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ‘uk’;

    btw I am going to try what you suggest for @Rose.

    Thanks again
    Prajosh

  27. Rose
    #27 | 8th July 2011

    Thanks Adam,

    I solved it, and both domains work fine,but I am still working on websites products, It has been removed after I did that mistake

    and one more question:

    How I can remove my posts here or at least edit it?

  28. Paul Young
    #28 | 8th July 2011

    Question, would this to work with this subdomain scenerio, would the htaccess code need to change?

    site1.domain.com/catalog
    site2.domain.com/catalog

    Magento resides in site1 folder.

  29. prajosh
    #29 | 13th July 2011

    Hi Adam

    Finally I solved the issue, actually the blank page issue was because of an extension.

    Thanks
    Prajosh

  30. Adam Moss
    #30 | 15th July 2011

    Paul – yes the htaccess would need to change to the appropriate subdirectory as you said.

    Prajosh – Glad you got it working, one of my first steps when debugging is always to disable extensions.

  31. Ponsakthi Anand
    #31 | 4th August 2011

    Hey Adam,

    above article was really informative, but one doubt

    i have one main domain installed in magento

    say for eg. http://www.domain.com
    my additional domain is http://www.domain2.com, http://www.domain3.com, http://www.domain4.com respectively

    now my question is

    if i click on any of my products the links are showing like

    http://www.domain2.com/domain2/product1.html (domain2 is my store code) instead of http://www.domain2.com/product1.html

  32. Geoff
    #32 | 5th August 2011

    Ponsakthi,

    Your issue is likely due to the fact that you have store code added to your urls. To turn this off, go to System > Config > Web (General) > Url Options. Set Add Store Code to Urls to NO.

    Adam Moss,

    First off, your method was the quickest and easiest multi-store/multi-domain method. Thank you for that!

    I second Patrick’s question though – “…if we have for instance two domains how do we sort out the SSL certificate issue? As this way we only have a single dedicated IP address which would be the master domain and the domain aliases would hence share that IP address.”

    I’m dealing with this issue as we speak and help would be MUCH appreciated.

    Thanks in advance!

    Geoff

  33. Guy
    #33 | 4th October 2011

    Hi Adam,

    I’ve currently got http://www.domain1.co.uk setup in Magento and have created a second store in the admin which is now at http://www.domain1.co.uk/secondstore which is a complete duplicate of http://www.domain1.co.uk apart from the change in branding but I want that one to read from it’s own domain which would be http://www.secondstore.co.uk which we also own and is already showing an old site at the moment but I want it to show the new secondstore Magento site. How do I do this? Would I still need to make http://www.secondstore.co.uk an alias of http://www.domain1.co.uk in Plesk and have I done it correctly setting it up initially in a sub folder?

    I’m fine with the design and basic Magento admin but baffled when it comes to the tricky stuff like this!

    Any ideas would be greatly appreciated!

    Guy

  34. Guy
    #34 | 5th October 2011

    Hi Adam,

    I figured it out in the end! This tutorial is by far the best I’ve come across over the last couple days. The one thing that’s worth pointing out is you make sure that in the configuration in the Magento admin you set… ‘Redirect to Base URL if requested URL doesn’t match it’ to ‘no’…sounds obvious I know but it is easy to miss that. Once I did that it worked! Brilliant. Anyone else out there stuggling stick with this tutorial, it really does work and I’m pretty hopeless when it comes to anything vaguely technical.

    Thanks again Adam!

  35. Dushyant Joshi
    #35 | 20th October 2011

    Thanx for a gr8 article. I want different name for admin only
    Like

    I have created three stores named “demo1.website.com”, “demo2.website.com” and “demo3.website.com”.

    And I want admin as “admin.website.com”

    Server is a Linux Box

    Please help

    Regard
    Dushyant Joshi

  36. Samuel Jordan
    #36 | 28th December 2011

    It’s helpful information for newbie. Thanks for posting.

  37. Anastasia
    #37 | 8th January 2012

    Thanks for the great article!
    It just worked only with a store for me on 1.5.1, not with a website. I tried for a few times doing exactly how it stands in the article, but always got a 404 error.
    Then I mentioned in my index.php ‘store’ but not ‘website’:

    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ‘default’;
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : ‘store’;

    So I just used the same in the .htaccess

    SetEnvIf Host www\.domain2\.co.uk MAGE_RUN_CODE=default
    SetEnvIf Host www\.domain2\.co.uk MAGE_RUN_TYPE=store
    SetEnvIf Host ^domain2\.co.uk MAGE_RUN_CODE=default
    SetEnvIf Host ^domain2\.co.uk MAGE_RUN_TYPE=store

    And it worked just fine.
    BTW trying to change index.php for website and it’s code showed an error.

    Hope it helps if someone becomes such a strange 404 error too.

  38. Patrick
    #38 | 17th January 2012

    Hi Adam.
    Congratulations! Nice and easy to understand tutorial. My issue is not about setting up the multidomain, i made that without any problems but moving the whole site to a new server (no changes in paths). Since i moved the site, all the secondary domains are loading the main domain instead of their respective website. No errors. Looks like to be the same problem as Wavi has. I double checked the .htaccess and the setup of the domains and all are pointing to the right location. Any suggestions?

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.