How to set multiple websites with multiple store views in Magento

Featured Image

If you work with Magento, sooner or later you will end up needing multiple websites that have
multiple languages.
Most of you know this, but I hope someone will still find this post useful.

There are few ways of doing same thing, but in my experience way I’m going to present now causes
less problems even though it is less automatic than some other ways.

Let’s say we want 2 websites and 2 languages for each site.

Here’s procedure:

In admin panel, go to System->Configuration and click on “Manage Stores”
Click on “Main Website” to change it’s name to “Website 1″ or however you want to call it. (I’ll call mine “Website 1″ for the purposes of this article).
In “code” field there, write something like “website_1″.

Do same for “Main Website Store”. Call it “Website store 1″.

And guess what… do same for “Default Store View” that you can find on same interface.
How to call it?
Hm… I’ll call mine “English Store View”
I’ll write “english_store_view_website_1″ in “code” field there.

Ok, let’s go make second one…
Add website named “Website 2″ with code “website_2″.
Add store called “Website store 2″ and assign it to Website 2 that you can chose from dropdown.
Add new store view called “English Store View” with code “english_store_view_website_2″ and
assign it to “Website 2″ that you can find in dropdown.

By now you should have 2 websites with 1 language each.

Add two more store views.
Call first “German Store View” with code “german_store_view_website_1″.
Call second “German Store View” with code “german_store_view_website_2″.
Assign them to corresponding websites.

Let’s see what we have at this moment:

1) a) Website 1 (code: website_1) – Website Store 1 English Store View (code: english_store_view_website_1)
b) Website 1 (code: website_1) – Website Store 1German Store View (code: german_store_view_website_1)

2) a) Website 2 (code: website_2) – Website Store 2 English Store View (code: english_store_view_website_2)
b) Website 2 (code: website_2) – Website Store 2German Store View (code: german_store_view_website_2)

Of course, I didn’t mentioned that you will need to chose root category for your stores, do what ever you like there.

Ok, let’s say we want url to be handled this way:
1) http://www.yourdomain.com/website_1
2) http://www.yourdomain.com/website_2

In your Magento installation directory, make 2 directories called “website_1″ and “website_2″
Copy .htacces and index.php from your root directory in each of those new directories.

In .htaccess search for “RewriteBase /” line and replace it with “RewriteBase /website_1/” in first directory, and
search for “RewriteBase /” line and replace it with “RewriteBase /website_2/” in second directory.

In both directories open index.php and change “$compilerConfig = ‘includes/config.php’;” to
$compilerConfig = ‘../includes/config.php’;

Change $mageFilename = ‘app/Mage.php’; to $mageFilename = ‘../app/Mage.php’;

In same file make sure to edit Mage::run() function for each site:

Mage::run(‘website_1′, ‘website’);
Mage::run(‘website_2′, ‘website’);

Go to System->Configuration and select Current Configuration Scope: Website 1

Set absolute paths to your skin, js and  media directories and set Base URL = http://www.yourdomain.com/website_1  (do that for website_2 too)

Now use this dirty way to switch between websites :)
http://inchoo.net/ecommerce/magento-snippet-for-switching-between-websites/

Since there is much to say about this subject, feel free to ask questions and I’ll try to answer them asap.

74
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Tomas Novoselic

Team Leader / Senior Developer

At Inchoo, Tomas is a Team leader and Certified Magento Developer. He handles Magento modifications at any level. He also works closely with clients on Magento projects of any size and difficulty.

Other posts from this author

Discussion 74 Comments

1 2
Add Comment
  1. Great article. Something I will refer to again.

    I spotted a suspect typo:

    Should it be GERMAN for the (B) examples?

    1) a) Website 1 (code: website_1) – Website Store 1 – English Store View (code: english_store_view_website_1)
    b) Website 1 (code: website_1) – Website Store 1 – GERMAN Store View (code: german_store_view_website_1)

    2) a) Website 2 (code: website_2) – Website Store 2 – English Store View (code: english_store_view_website_2)
    b) Website 2 (code: website_2) – Website Store 2 – GERMAN Store View (code: german_store_view_website_2

  2. @Medden U R right! Article updated. Tnx!

  3. This is a nice summary on how to setup a magento multistore. If I see it right this is for magento 1.3.x.x version.

    I’m not sure if I got it right from the documentation on the internet, but since version 1.4.x.x. what you have to change in the index.php file is
    $compilerConfig = ‘includes/config.php’;
    and/or ( depending on the server/hosting package you have )
    $mageFilename = ‘app/Mage.php’;
    to the right path and add your store code to this line
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ”;

  4. @Igor, yes, U R right, since 1.4 things are done differently.
    Thing is that described method works 1.3 AND on 1.4 so I decided to write article that way :)

  5. dimas9999

    Oooo. it’s nice post. I doing second shop on this CMS now…

  6. bare

    Great post.

    I’d like to see the way to do in magento 1.4. I’ve read in the magento’s wiki site though, but it didn’t work because i’m confuse that wether should i create new index.php and .htaccess or not?

  7. Yaaaay! Finally I got it working in some form! However this does not work with SEF URLs turned on :( Any clues how to get it working and still have nice looking urls?

    Also would be great to see a description of Magento 1.4 specific method for both subdirectory and subdomain cases.

  8. Hi,

    Is it absolutely necessary to have separate subdirectories and separate index.php files? Reading http://blog.baobaz.com/en/blog/setting-up-magento-with-multiple-websites-or-stores implies that only one is necessary, or am I missing something?

    Thanks,
    JD

  9. I’ve recently set-up Magento 1.4.0.1 to run two websites on two separate subdomains, but this would also work nicely for different domains as long as they are hosted on the same account.

    Assuming you have already created another website in Magento config… First thing to do is to point both of your subdomains/domians to the same document root in your hosting settings, so that they both load your Magento Home Page. All other pages will be loading with your primary domain in url – this is how it should be.

    Next, 1.4 tutorial for multiple websites tells us to either use Virtual Host (which I did not have) or .htaccess method (which did not work for me either), but I used this piece of code in my index.php and it worked like a charm:

    if ($_SERVER['HTTP_HOST'] == “sub.mydomain.com”){
    $_SERVER["MAGE_RUN_CODE"] = “website_code”;
    $_SERVER["MAGE_RUN_TYPE"] = “website”;
    }

    repeat this for every website you have and place it right before:

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

    Then also go and set Base URL in Magento config to match your domain/subdomain.

    Clear Cache and try opening both (or more) of your websites in browser.

    Hope this helps!

  10. Thanks @konstantin, I found the same. I couldn’t get the .htaccess method to work, though I do wonder if it’s because I’m using the ServerAlias directive in my apache vhosts.

    @Tomas, fair enough, good to know. The solution that @konstanin and I have working don’t need different sub-dirs which is much cleaner.

    Next challenge is to migrate 1.3.2 phtml mods into the 1.4.0.1 theme files, ahh backwards compatibility…

  11. clockman

    i have 1.4 magento
    i made everything working with subfolder /wholesale store
    the /wholesale is opening but without theme. i want the default theme for that store too. do i miss something?

  12. You need configurated base links for new website:
    System-Configuration-Web. Select New shop in the left drop-down menu and edit unsecure and secure fields.

  13. Linda

    … dumb question here… When you say Mage::run(‘website_1′, ‘website’);
    does one use the word “website” or is that supposed to be a path?
    Thank you, Inchoo people!

  14. Linda

    Sorry, should clarify. I understand that website_1 is the name of the subdirectory. It’s ‘website’ I’m not sure about.

  15. In you example “website_1″ is an id/code of either website or store_view, so the second variable tells the system to look for a website with this code. Optionally you can pass “store”, so that system will load store_view with given id/code.

    That way you can have either a website or a language (store view) on a different url/domain, and whenever anyone goes to that url, Magento will load appropriate store view or website.

    Hope this helps :)

  16. Linda

    Thanks! I’m still working on it. I hope it helps too!

  17. Atmanbill

    Hi Konstantin & Jonathan,

    I modified the index.php following your instruction, but then when I opened http://www.myseconddomain.com in browser, I was taken to http://www.mybasedomain.com

    I have set base urls for both base domain and my second domain. I have cleared cache.

    Did I miss any step? Please help me. Thank you in advance.

    Atman

  18. @Atmanbill

    What version of Magento are you using? Did you configure your web server for http://www.yourseconddomain.com to point to the same document root as http://www.yourbasedomain.com? It should not be forwarded or dedirected, it should be just pointing to the same document root as your primary domain. All other settings sound ok.

  19. Atmanbill

    Hi Konstantin,

    I used magento 1.4.

    And yes, both primary domain and addon domain have the same document root: /public_html/

    Now I will still be redirected to my primary domain even when I visit the addon domain.

    It’s really frustrating!

  20. Give me a shout here: osyris [at] gmail.com and we’ll work something out for you :)

  21. Atmanbill

    Hi Konstantin,

    I have sent an email ” Re: Atman’s magento store ” to you. Please have a check.
    Thanks for your time my friend.

  22. Atmanbill

    Hi Konstantin,

    Finally I figured out what’s wrong.
    I disabled redirection in cPanel, then I wouldn’t be redirected to my primary domain when I visited the addon domain.

    Thanks a lot my friend!

  23. Kyle Slater

    Hi – with multiple stores, can you filter orders by store in the admin section? This seems like it would be critical for reconciliation.

    Thanks

  24. Yes you can, just like switching between Store Views (languages)

  25. Kissthesky

    Hi,
    Can you please update this for v1.4.1 – I’m in the process of doing this and i just can’t see to get a break on how to do it.
    Will appreciate it great deal if you could help.

    Thanks

  26. @Kissthesky
    Everything described in my post from May 14th, 2010 is still valid for 1.4.1

  27. sunil

    i have installed magento om my primary domian like Maindomain.com/ now the url of this main domian is Maindomain.com/StoreviewCode/Category/SubCategory.its fine for me. now i have also create a another add on domain def.com on server.now how can i make the url for this add on domin like def.com/Category/subcategory i dont want to include this StoreviewCode in add on domain url.please provide the solution how can i do it..thanks so much

  28. Correct me if I am wrong, but I believe “add store code to url’s” is a global setting, that you can not override within one installation. So you’ll either have to “hack” you way through or use another instance of Magento. If you do find a nice hack for this, please share!

    Good luck.

  29. What about setting up sort order especially when you are creating multiple store view? aren’t that important at all? How to setup default language store view?

  30. developer27

    Hello,
    I am going to develop a website for multiple store[each store has its own separate domain name] with single shopping cart. So that user can see all added products in cart at any website [in cart all other website added product will also show].
    Can anyone please help me to develop that system in magento1.4
    I need urgently. If some one explain with code in steps then its good to me.

    Many thanks in advance….

  31. @developer27

    I can help you with it, but not for free. Write to osyris@gmail.com if you’re interested.

  32. I can’t get the second site /wholesale to show up with a theme. It’s not even picking up the defualt theme. Please what am I doing wrong?

  33. Well, I have 2websites each with a single store and view.
    http://GlucALite.com the main store, and another at a folder.

    I REALLY really need to be able to put a folder to bring up just a different store view, so I have one website, one store and multiple store views. to get rid of the second store. how do I do this??!

  34. Leeburstroghm, what exactly are you after? What do you mean by “I need to be able to put a folder to bring up just a different store view”. What is it that you’re trying to achive? Do you want to assign existing Store Views to a different Store in your installation, or do you want your Store Vies to be accessible on different URLs?

  35. Thanks for your reply and interest, I FIGURED it out YAY. Finaly.

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

    Mage::run($mageRunCode, $mageRunType);

    and then had my store view configuration links set and now everything works as expected, You have to use the STORE_VIEW_NAME for the CODE and STORE for RUN_TYPE and not the STORE_NAME-code!!! I thought it was the Store-Name and the default view would display.

    this works Perfect now !YAY!

    What I was referring to is exactly like 2 different website-stores either as subdomains or subdirectories, but to have a 2 stores under the same website, or 2 separate store VIEWS under the same website-store, to appear with different and unique subdirectories

    Doman.com / subdir etc…

  36. Hayden

    @snlaurio,

    I am having the same issue. I am using 1.4.2.x. It seems to load properly (even though it takes a lot longer).

    Here is my setup:

    mydomain.com (default store)
    mydomain.com/wholesale (wholesale store)

    My settings under “Web” are as follows:
    Unsecure:
    http://www.mydomain.com/wholesale/
    {{unsecure_base_url}}wholesale/

    Secure:
    https://www.mydomain.com/wholesale/
    {{secure_base_url}}wholesale/

    I’ve followed the instructions to the “t” on every website thus far and still haven’t been able to get this to work properly. I am simply tring to setup a “Wholesale” store. Can anyone please help? Thanks!

  37. Andre Klang

    Hi,
    In your setup you have English and German in two places. If you enter English product descriptions and titles in global scope, wouldn’t you have to enter the German texts two times?
    One for each storefront?

    Nobody has been able to answer me on this simple question..

    Thanks

  38. Mike

    Can my main website have sub websites, with each sub website having its own shopping cart and payment gateway? as well as admin login and reporting capabilities.

  39. how can i use the mulitpal store with diffrent langues and diffrent view, for eg, 2nd store is german langue but i need some color and layout changes in 2nd sotre, is it possible?

  40. @jawad
    Most of the settings in Magento can be applied on 3 levels: Global Level – applies to all websites, Stores and Store Views (languages); Website Level – applies to a particular website and it’s Store Views; Store View Level – applies to a particular Store View. In your case you could assign a different design to a German Store View. The term “different design” however does not mean you’ll need to have a full copy of a theme, but only those files from your original theme that need to be different. Let’s say you theme’s CSS is in skin/frontend/default/your_theme/css/styles.css, in that case you will need to make a copy of styles.css and put in into skin/frontend/default/your_theme2/css/styles.css. In Admin go to System>Configuration>Design>Themes. Swith Current Configuration Scope to your second Store View (German language). Type your_theme2 (name of the copy of your original theme) into Skin (Images / CSS) box. Make Sure that Default box has your original theme name in it.

    Now, whichever changes you make to styles.css under your_theme2 will only be reflected in you German Store View. Following the same logic you could make copies of template and layout files.

    This is a big topic that requires understanding of how Magento theme and settings hierarchy works. Hope this helps!

  41. @Konstantin
    Thanks for sharing great information, i really appreciate it, and i am trying to implement trick with your help, basically my client need site in 2 lang , big problem is 2nd lang is in RTL ( arabic) thats why i face problem, he want same like this function http://www.gonabit.com/dubai/ in arabic you can see layout change according to arabic lang, i hope now you understand that wat i looking for
    thanks

  42. Yes, I believe that with a combination of and adjusted to RTL theme’s .xml (to reassign blocks to new positions where necessary) and .css (to float and allign elements to opposite sides) files should give you the desired result.

  43. Sorry, missed one bit…

    Yes, I believe that with a combination of and adjusted to RTL theme’s .xml (to reassign blocks to new positions where necessary) and .css (to float and allign elements to opposite sides) files should give you the desired result.

  44. great, thanks for help, am trying to implement and after that i will share with link of Groupon clone http://bestgrouponclone.com/latest_code/test/index.php/ please check
    thanks

  45. hi guys, i have fix every thing but problem is which things are in

    __(‘text’); ?>

    that is auto translate or easy to translate with blocks, but which things are in that is not translateable please check the site and help me

    http://bonaty.com/

    in the footer you can change the lang
    thanks

  46. opps code is not appear

    __('text is autotranslate in this code') ?>

    but which text come with veriable or like this what is not translateable

  47. <?php echo $this->__('this text is translatebale') ?>

    this text not translatable , please help , how i can put this to auto translate

    <?php echo $_description; ?>
  48. Well, have you tried:

    <?php echo $this->__($_description) ?>
    

    Also, just to make sure you understand how translations work in Magento… The method above will only produce a translated string if that string and it’s translation are present in one of the .csv files under app/locale/your_language/. So if you are trying to translate a custom text, it will not work.

  49. @Konstantin
    I LOVE YOU, always keep you in my prayers, you are amazing sir, now problem is solve and i have done the things with your guideness
    thanks sir

1 2

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top