I'm not sure if your application configuration is correct. In my opinion you don't need to make redirection with .htaccess
. So here are couple of checkpoints:
1) Check that you have set a correct Base secure and unsecure URLs in Back Office (Admin Panel) for each store view (subdomain)
System > Configuration > Web > (Un)secure > Base Url
By default there should be http://store.com, and for each website (regarding Magento scope) URL should be different.
2) Cookie domain must be set for each store view respectively.
System > Configuration > Web > Session Cookie Management > Cookie Domain
For the default store you can leave it empty, but you must fill it for others, e.g. .sub1.store.com
, .sub2.store.com
, etc. Note that dot ('.') at the beginning is mandatory.
3) Set Apache vhosts for each domain.
You should have separate entries for site.com
, sub1.site.com
, etc in your vhosts configuration.
Now you can define which store view to load based on the domain. You can do this in 3 ways:
- .htaccess
- modify index.php of application
- set proper Env variable directly in vhost
In this post you can find each mentioned solution.
While dealing with multiple store views and domains with Magento it is all about to load a proper store code in Mage::run()
method.
Here's an example for .htaccess
solution:
SetEnvIf Host .*sub1.site.com.* MAGE_RUN_CODE="sub1"
SetEnvIf Host .*sub2.site.com.* MAGE_RUN_CODE="sub2"
Don't forget to flush cache and perform reindex of all entities after you set is all correct.