magento redirects to another subdomain based on co

2019-09-18 08:28发布

问题:

I have a magento store but currently decided to add other stores to separate the inventory and also have a clean catalog so i decided to create stores and host them on sub-domains like electronics.mydomain.com and sport.mydomain.com. i followed this tutorial http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/ but after it the sub-domains were still redirecting to main domain like www.mydomain.com even though i had done nothing with my .htaccess, i found a way to go about it by opening the index.php in my subdomain directory and adding $_GET['___store']= "STORECODE"; and also in my admin panel i typed .mydomain.com in the cookie field and also prolonged the duration to 1 day.

Voila.. everything is working now perfectly until i realized there was a problem, whenever i visit any of my stores(which is installed on the subdomain) and then try to open my main domain that is the www.mydomain.com, it redirects to subdomain.mydomain.com(which is the url of the last subdomain i checked) but then it works again after clearing cookies, i realized the problem is that magento is saving the current store id in the cookie so when i opens my main domain and the cookie is read, that store is returned and therefore the redirect. Okay , now i have been able to remove the SID from the url and everything works as they share the same cookie domain, now i noticed if i accessed my link like welspot.com?_store=default, the main site opens without a redirect to the subdomain, i was hoping then that anybody could help me redirect all incoming requests under my main domain to mydomain.com?_store=default.

As i still have the problem of cookie redirect, i have hard-coded $_GET['store']="default"; into my index.php file at the head in the main magento installation and now everything works right but there is another problem, when i go to the categories field and i try to select any categories it doesn't select, it just displays create new category instead of selecting and editing the click category and i think it has something to do with adding $_GET['store']="default"; in my index.php because when i remove it everything works but when i remove it and visit my site as welspot.com, based on the recent subdomain i visited it redirects there and i seriously need to solve this problem.

回答1:

Rather than editing the index.php on each store (which is a maintenance hassle), what I'd do is use the Virtual Host or .htaccess solutions described in this blog post to set an environment variable containing the unique store codes for each store. In a nutsell add the lines

SetEnv MAGE_RUN_CODE "base" # put here your website or store code
SetEnv MAGE_RUN_TYPE "website" # put here 'website' or 'store'

Into your virtual host, or:

SetEnvIf Host electronics.mydomain.com MAGE_RUN_CODE="base";
SetEnvIf Host electronics.mydomain.com MAGE_RUN_TYPE="website";

into your .htaccess. Make sure you also do this on the main domain as well, to set the default store code.

Also log into the back end, and go to System > Configuration. And select the "Web" option, where you'll see the Secure and Unsecure URLs for your site. Now select each store from the "Current Configuration Scope" dropdown at the top left and change the URLs to match the virtual hosts you've got set up (untick the "Use Default" box and enter the new url). This should stop the redirection you're seeing, as Magento is now aware of each store's unique subdomain.



回答2:

i recommend you realize the new domain in other way. You can view this in this blog:

In Spanish:

http://www.elblogdeselo.com/magento-configurar-multiples-stores-y-multiples-websites

in English:

http://blog.baobaz.com/en/blog/setting-up-magento-with-multiple-websites-or-stores?page=1 Hope help you.