How to set multiple websites with multiple store views in Magento

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 🙂
https://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.