简体   繁体   English

magento基于多商店中的cookie重定向到另一个子域

[英]magento redirects to another subdomain based on cookie in multistores trick

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 . 我有一家magento商店,但目前决定添加其他商店来分隔库存,并且拥有一个干净的目录,因此我决定创建商店并将其托管在子域中,例如electronics.mydomain.comsport.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"; 我按照本教程http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/进行了操作,但在此之后,即使我将子域重定向到了像www.mydomain.com这样的主域,我的.htaccess没有做任何事情,我找到了一种解决方法,方法是在子域目录中打开index.php并添加$_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. 并且在管理面板中,我在Cookie字段中输入了.mydomain.com,并将持续时间延长至1天。

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. Voila ..现在一切正常,直到我意识到有问题为止,每当我访问我的任何商店(已安装在子域中),然后尝试打开我的主域www.mydomain.com ,它将重定向到subdomain.mydomain.com (这是我检查的最后一个子域的URL),但是在清除cookie后它又可以工作,我意识到问题是magento将当前商店ID保存在cookie中,所以当我打开我的主域时并读取cookie,返回该存储区,并因此进行重定向。 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? 好的,现在我已经能够从url中删除SID,并且一切正常,因为它们共享同一个cookie域,现在我注意到,如果我访问了welspot.com?_store=default之类的链接,主站点将打开而无需重定向到子域,我希望那时有人可以帮助我将主域下的所有传入请求重定向到mydomain.com吗? _store=default. _store =默认。

As i still have the problem of cookie redirect, i have hard-coded $_GET['store']="default"; 由于我仍然遇到Cookie重定向的问题,因此我已硬编码$_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"; 进入我的主要magento安装头部的index.php文件中,现在一切正常,但是还有另一个问题,当我转到类别字段并且尝试选择未选择的任何类别时,它将显示创建新类别,而不是选择和编辑点击类别,我认为这与添加$_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. 在我的index.php中,因为当我删除它时一切正常,但是当我删除它并以welspot.com的身份访问我的网站时,基于我最近访问的子域,它会重定向到该地址,因此我非常需要解决此问题。

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. 与其在每个商店上编辑index.php(这很麻烦),我要做的是使用本博文中描述的Virtual Host或.htaccess解决方案来设置一个环境变量,其中包含每个商店的唯一商店代码。 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. 进入您的.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. 并选择“ Web”选项,您将在其中看到站点的安全URL和不安全URL。 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). 现在,从左上角的“当前配置范围”下拉列表中选择每个存储,并更改URL以匹配您已设置的虚拟主机(取消选中“使用默认值”框并输入新的URL)。 This should stop the redirection you're seeing, as Magento is now aware of each store's unique subdomain. 这应该会停止您正在看到的重定向,因为Magento现在知道每个商店的唯一子域。

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 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. http://blog.baobaz.com/en/blog/setting-up-magento-with-multiple-websites-or-stores?page=1希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM