There are many tutorials how to set Magento to work with multiple stores and make different domains point at each store. Since release of Magento CE 1.4.0.0-beta1 and Magento EE 1.6.0.0 it is even more easy to do.
Magento evolves
Solutions used in previous versions required developer to modify index.php file to handle different domains pointing at different stores. New index php contains following code:
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);
So it checks two environmental variables and use them to start Magento runing. What does it give you? You can set now which store/website is supposed to be running under selected domain directly in virtual host definition or even htaccess.
VirtualHost solution
To benefit from this little piece of code it is enough for you to add following lines within your VirtualHost definition:
SetEnv MAGE_RUN_TYPE "website" # put here 'website' or 'store'
.htaccess solution
If you have no access to virtual host definitions, you can still try to use .htaccess for that, putting within following lines:
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE="website";
Where .*yourhost.* is an regex expression matching the domain for which you want to set environmental variable.
So now you are capable of setting up your Magento multiple stores website without messing up with the core. Good luck.







I understand the code, I see the new field in the back-end, but why is type "website" or "store"?
Is this suppose to be set whether it goes to the Website or Store View?
@Rich: You are always on the Store View, but you may be on particular one, or default one. If you will use 'website' and will give Website code you will land on specified Website's default store's default Store View. If you will use 'store' and will give Store View code, then you will find yourself on the specified Store View.
As a matter of fact there is also a 'group' type valid, which would lead to default Store View for the Store, and it seems that code you have to provide in this case is the Store's (store_group) id value.
I don't know if this is for every type of setup, but I found that for the .htaccess method you have to remove the quotes around the values and also the semi-colon like so
SetEnvIf Host .*yourhost.* MAGE_RUN_CODE=base
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE=website
Hi, I am busy an all day and night trying to get this fixed and I do not succeed! Can you please help me?
I want to get URL's to website's
In advance thanks for your help!
Hi, I am on Magento 1.4.0.1
Thanks for this post, I almost lost my hairs on that.
I made that on index.php:
$mageRunCode = isset($_SERVER[’MAGE_RUN_CODE’]) ? $_SERVER[’MAGE_RUN_CODE’] : ‘newbesite’;
$mageRunType = isset($_SERVER[’MAGE_RUN_TYPE’]) ? $_SERVER[’MAGE_RUN_TYPE’] : ‘website’;
And turn “Redirect to Base URL if requested URL doesn’t match it” to “NO” in the admin
It works for me to get to my “newwebsite”, but now I can get to my “base” website! or to other websites!
So how and what to configure for multi websites?
Regards.
Hi Conec,
What code did you put in your .htaccess file? What is URL or your base and newwebsite?
For example if URL of you base is www.base.com and URL of your newwebsite is www.newwebsite.com you should put following code in your .htaccess
SetEnvIf Host .*newwebsite.* MAGE_RUN_TYPE="newwebsite";
Regards
Hi, Mag 1.4.0.1 I'm on a dedicated server.
I have set up my first 10 websites in Magento and pointed all 10 urls to my nameserver. In addition, I have set up each store within the admin to the correct urls. I tested them and they are all landing on the main domain, so I think I'm to this step now (correct me if I'm wrong please).
1. How would I change my index.php for multiple domains? Is this the best way to do multiple domains? In the end I might have close to 300 domains pointing to one instance of Magento.
2. I was told to park all of my domains under the Main domain in Cpanel where Magento is installed. Is this recommended?
3. Will these domains be able to share the same cart under one SSL?
Obviously, I'm new to all of this but trying to make my way through it so any feedback would be great. I think once I get the first few set up the other 200+ will be easy. I just want to make sure I get started in the right direction.
version 1.4.0.1
It did not work. Can some one guide me how to add multiple sites. I dont know mush about it and if anyone can send steps then I will really indebted.
hardly urgent. pls help me.
I would like so more detail if anyone is willing to help?
I have Magento 1.4 installed at mydomain.com/magento.
I have created two additional websites store1 & store2 in Magento admin. I would like the subdomains store1.mydomain.com & store2.mydomain.com to point to the the added websites respectively. When I create these subdomains using cPanel they create new directories, mydomain.com/store1 & mydomain.com/store2. What code do I need to enter and in which .htaccess files?
I beg for your help. I'm a novice and need this sorted.
James
I’m currently running 2 websites from one Magento installation and I want to enable Web Server Rewrites for SEO. However, when I do this, I’m getting a 404 Not Found error for the page I’m navigating to. It works fine when rewrites are turned off.
Rewrites are enabled in Apache and rewrites do work on the base website. It just wont work on the external websites.
Any ideas?
Here another simple solution:
if ($_SERVER['HTTP_HOST'] == "someotherdomain.com"){$_SERVER["MAGE_RUN_CODE"] = "yourcode";
$_SERVER["MAGE_RUN_TYPE"] = "website";
}
before:
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';Note: I set up the second store as website - not as store.
Hi Mike,
I was wanting to know if you ever got this working? I am trying to do the exact setup as you are.
I have successfully set up a multi store environment, but I am unable to share the cart. I know I have something wrong and was hoping you could shed some light on this for me.
We have our own server and have setup the different Url's to point to the root document of the main site. Then I have the other domains parked.
In my index.php I have something like this....
switch($_SERVER['HTTP_HOST']) {
case 'site1.com':
case 'www.site2.com':
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'site1';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);
break;
Can you tell me how you did it?
hi, guys,
do anybody solve this ?
i am losing my hair everyday right now.
waiting for solutions....
Hi ,
I have the problem like this(my service: debian+apache2+php5.26+...): and i am going to set different website to the same bacekend but with different IPs and SSL.
1,newly installed magento 1.4.0.1 on "domain1.com" with code "base", this domain has IP "IP1"
2,and then am i setup another visul host "domain2.com" , which come with IP "IP2",
3,add new website to the back end with code "domain2"
4,as the expeirence of http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/, i did copy index.php and .htaccess to the root fold of domain2.com .../domain2/public_html/
5, reate symbolic links to point to the folds of /domain1/public_html/
6,then i add the code to ... /domain2/public_html/.htaccess
SetEnvIf Host .*domain1.com.* MAGE_RUN_CODE="domain1";
SetEnvIf Host .*domain2.com.* MAGE_RUN_TYPE="domain2"
;
and now when i try to access to domain2.com, i got:
app/Mage.php was not found
Here i am totally new to magento, so can you please help to tell me where is the problem ? or did i do not need to step4-6, and only need to add the code to ../domain1/public_html/. htaccess ?
Thank you in advance.
Frank
Hi,
I don't understand your method
In my example i have one domain : domain.com
i create two store on the same domain : domain.com
what is the procedure for this configuration
Thank you in Advance
I am also having trouble with this. I have one domain with multiple stores setup. I have one Magento installation setup on my domain (www.example.com). I have setup two stores: retail, wholesale. I want my primary domain to be the retail store and would like my wholesale store to be a subdomain (wholesale.example.com). How do I setup my Magento Installation to do this? Thanks in advance.
In my opinion, the cleanest solution is to use vhost configuration :
<VirtualHost *:80>
DocumentRoot "C:/www/magento/"
ServerName magento.local
ErrorLog "logs/magento.local-error.log"
CustomLog "logs/magento.local-access.log" common
<Directory "C:/www/magento">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
# mobile website
<VirtualHost *:80>
DocumentRoot "C:/www/magento/"
ServerName mobile.magento.local
ErrorLog "logs/mobile.magento.local-error.log"
CustomLog "logs/mobile.magento.local-access.log" common
SetEnv MAGE_RUN_TYPE "website"
SetEnv MAGE_RUN_CODE "mobile"
<Directory "C:/www/magento">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
James,
Just curious if you've got this one figured out. We have the same setup -- main site with two other domains which point to subdirectories that were created in the store root, so when the url is requested, it goes to the subfolders instead of the root folder and bypasses the .htaccess file where these rules are stored. Can anyone give me advice on how to solve that? Thanks.
You will also need to insert additional entries to the core_config_data table. If you've got one site already, you'll see one entry each for "web/unsecure/base_url" and "web/secure/base_url" in that table. Add 2 more entries for "web/unsecure/base_url" and "web/secure/base_url" with scope_id set to the related store_id found in the core_store table. Update their values to the new store URL.
I've only been working with Magento for 3 days, so there may be a better/proper way of doing this so feel free to suggest an alternative :)
I found the same, it's necessary to remove the double quotes AND the semi-colon
Hi James,
Did you figure it out yet?
thanks
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
I am struggling with this for a few days now and tried every option discripted here. Unfortunatly I am not able to get everything working. I have got working 1 basestore and one substore, there is just 1 session made when I want to order on both of them, but I still have to seperate carts. I am working with version 1.4.1.0.. Does someone have a suggestion to try?
Thank you in advance.
Peter
Alex, thanks a lot, your solution works great and is the simplest.
I just added this switch before the assignment for $mageRunCode and $mageRunType:
switch ($_SERVER['HTTP_HOST']) {
case "www.myfirstdomain.com":
$_SERVER['MAGE_RUN_CODE'] = "myfirstwebsite";
$_SERVER['MAGE_RUN_TYPE'] = "website";
break;
case "www.myseconddomain.com":
$_SERVER['MAGE_RUN_CODE'] = "mysecondwebsite";
$_SERVER['MAGE_RUN_TYPE'] = "website";
break;
//etc
}
Regards,
Adrian
Post new comment