{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/3676","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/3676/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/3676/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/3676/events","html_url":"https://github.com/magento/magento2/issues/3676","id":139018853,"number":3676,"title":"Store switch endless loop, wrong navigation block content (wrong store) with multidomain/language setup","user":{"login":"m-strojek","id":17046842,"avatar_url":"https://avatars.githubusercontent.com/u/17046842?v=3","gravatar_id":"","url":"https://api.github.com/users/m-strojek","html_url":"https://github.com/m-strojek","followers_url":"https://api.github.com/users/m-strojek/followers","following_url":"https://api.github.com/users/m-strojek/following{/other_user}","gists_url":"https://api.github.com/users/m-strojek/gists{/gist_id}","starred_url":"https://api.github.com/users/m-strojek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-strojek/subscriptions","organizations_url":"https://api.github.com/users/m-strojek/orgs","repos_url":"https://api.github.com/users/m-strojek/repos","events_url":"https://api.github.com/users/m-strojek/events{/privacy}","received_events_url":"https://api.github.com/users/m-strojek/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/magento/magento2/labels/PS","name":"PS","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-07T16:12:17Z","updated_at":"2016-03-09T12:43:54Z","closed_at":null,"body":"**Steps to reproduce**\r\n--\r\n1. Install Magento release 2.0.2)\r\n1a. Disable Fullpage and block cache (just to avoid caching effects)\r\n2. Setup multistore setup with nginx:\r\nThis setup is meant to handle country domains with a (not unique between stores) language prefix for urls.\r\n\r\nE.g. \r\nhttp://mysite.de/\r\nhttp://mysite.de/en-DE/\r\nhttp://mysite.at/\r\nhttp://mysite.at/en-AT/\r\nhttp://mysite.ch/\r\nhttp://mysite.ch/en-CH/\r\n\r\n\r\na)\r\nserver {\r\n\tserver_name mysite.de\r\n\r\n\t# handle default requests\r\n\tlocation ~ (index|get|static|report|console|404|503)\\.php$ {\r\n\t\r\n\t    # set base store for this domain\r\n\t\tfastcgi_param MAGE_RUN_CODE base_de_de;\r\n    \tfastcgi_param MAGE_RUN_TYPE store;\r\n    \r\n    \tfastcgi_index  index.php;\r\n    \tfastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\r\n\r\n    \tinclude        fastcgi_params;\r\n    }\r\n    # handle language code requests like mysite.de/en-DE/...\r\n    location ~ \"\\/([a-zA-Z]{2})\\-([a-zA-Z]{2})(\\/?)(.*)$\" {\r\n\r\n        fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_de\r\n        fastcgi_param MAGE_RUN_TYPE store;\r\n        \r\n        fastcgi_index  index.php;\r\n        fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;\r\n\r\n        include        fastcgi_params;\r\n\r\n        # overwrite paths with cleanup of language code\r\n        fastcgi_param  REQUEST_URI $3$4;\r\n    }\r\n}\r\n\r\nb)\r\n\r\nserver {\r\n\tserver_name mysite.at\r\n\r\n\t# handle default requests\r\n\tlocation ~ (index|get|static|report|console|404|503)\\.php$ {\r\n\t\r\n\t    # set base store for this domain\r\n\t\tfastcgi_param MAGE_RUN_CODE base_de_at;\r\n    \tfastcgi_param MAGE_RUN_TYPE store;\r\n    \r\n    \tfastcgi_index  index.php;\r\n    \tfastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\r\n\r\n    \tinclude        fastcgi_params;\r\n    }\r\n    # handle language code requests like mysite.at/de-AT/...\r\n    location ~ \"\\/([a-zA-Z]{2})\\-([a-zA-Z]{2})(\\/?)(.*)$\" {\r\n\r\n        fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_at\r\n        fastcgi_param MAGE_RUN_TYPE store;\r\n        \r\n        fastcgi_index  index.php;\r\n        fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;\r\n\r\n        include        fastcgi_params;\r\n\r\n        # overwrite paths with cleanup of language code\r\n        fastcgi_param  REQUEST_URI $3$4;\r\n    }\r\n}\r\n\r\nc)\r\nserver {\r\n\tserver_name mysite.ch\r\n\r\n\t# handle default requests\r\n\tlocation ~ (index|get|static|report|console|404|503)\\.php$ {\r\n\t\r\n\t    # set base store for this domain\r\n\t\tfastcgi_param MAGE_RUN_CODE base_de_ch;\r\n    \tfastcgi_param MAGE_RUN_TYPE store;\r\n    \r\n    \tfastcgi_index  index.php;\r\n    \tfastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\r\n\r\n    \tinclude        fastcgi_params;\r\n    }\r\n    # handle language code requests like mysite.at/de-AT/...\r\n    location ~ \"\\/([a-zA-Z]{2})\\-([a-zA-Z]{2})(\\/?)(.*)$\" {\r\n\r\n        fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_ch\r\n        fastcgi_param MAGE_RUN_TYPE store;\r\n        \r\n        fastcgi_index  index.php;\r\n        fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;\r\n\r\n        include        fastcgi_params;\r\n\r\n        # overwrite paths with cleanup of language code\r\n        fastcgi_param  REQUEST_URI $3$4;\r\n    }\r\n}\r\n\r\n\r\n\r\n3. Store Configuration\r\nStore 1:\r\nName: My Store (Renamed the default)\r\nRoot Category: use default\r\nDefault Store View: DE - DE\r\n\r\n\r\nWebsite 1 (Default):\r\n========== \r\nName: My Website (Renamed the default)\r\nCode: base\r\nDefault Store: My Store\r\n\r\nStore Views 1:\r\n==============\r\nName: DE - DE (renamed default)\r\nCode: base_de_de\r\nBackend Base Url: http://mysite.de/\r\nBackend Base Link Url: http://mysite.de/\r\n\r\nStore Views 2:\r\n==============\r\nName: EN - DE\r\nCode: base_en_de\r\nBackend Base Url: http://mysite.de/\r\nBackend Base Link Url: http://mysite.de/en-DE/\r\n\r\nStore Views 3:\r\n==============\r\nName: DE - AT\r\nCode: base_de_at\r\nBackend Base Url: http://mysite.at/\r\nBackend Base Link Url: http://mysite.at/\r\n\r\nStore Views 4:\r\n==============\r\nName: EN - AT\r\nCode: base_en_at\r\nBackend Base Url: http://mysite.at/\r\nBackend Base Link Url: http://mysite.de/en-AT/\r\n\r\nStore Views 5:\r\n==============\r\nName: DE - CH\r\nCode: base_de_ch\r\nBackend Base Url: http://mysite.ch/\r\nBackend Base Link Url: http://mysite.ch/\r\n\r\nStore Views 6:\r\n==============\r\nName: EN - CH\r\nCode: base_en_ch\r\nBackend Base Url: http://mysite.ch/\r\nBackend Base Link Url: http://mysite.de/en-CH/\r\n\r\n\r\n**Expected result**\r\n\r\n1. Switching between stores will work as expected\r\n2. Content will be shown as configured for the store\r\n\r\n\r\n**Actual result**\r\n\r\n1. Switching between stores works some time - but at some point you can't get back to the default stores views.\r\nAdditional, at some time endless redirect loops occur between 2 of the stores after switching.\r\nCan only be fixed by closing browser AND clearing session table AND clearing cache via commandline.\r\n\r\n2. If you call the store with mysite.de you will get \r\na) OK a correct store switcher preselection\r\nb) OK a correct content (some configured cms page)\r\nc) NOT OK Top Navigation links will show links with a \r\nlanguage/country prefix and url from the other store (e.g. mysite.ch/en-CH/somecategory.html even if you are on mysite.de.\r\nReload of the page will sometimes bring the correct results for the store, sometimes navigation from an other store (wrong too).\r\nI even checked the context in the navigation block by echo of store id: it's correctly showing the expected store. \r\n\r\nHope that someone has an idea what went wrong here. \r\n"},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/194280015","html_url":"https://github.com/magento/magento2/issues/3676#issuecomment-194280015","issue_url":"https://api.github.com/repos/magento/magento2/issues/3676","id":194280015,"user":{"login":"m-strojek","id":17046842,"avatar_url":"https://avatars.githubusercontent.com/u/17046842?v=3","gravatar_id":"","url":"https://api.github.com/users/m-strojek","html_url":"https://github.com/m-strojek","followers_url":"https://api.github.com/users/m-strojek/followers","following_url":"https://api.github.com/users/m-strojek/following{/other_user}","gists_url":"https://api.github.com/users/m-strojek/gists{/gist_id}","starred_url":"https://api.github.com/users/m-strojek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-strojek/subscriptions","organizations_url":"https://api.github.com/users/m-strojek/orgs","repos_url":"https://api.github.com/users/m-strojek/repos","events_url":"https://api.github.com/users/m-strojek/events{/privacy}","received_events_url":"https://api.github.com/users/m-strojek/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T12:43:54Z","updated_at":"2016-03-09T12:43:54Z","body":"I figured out a modification which fixes the problem of endless redirects / wrong redirects.\r\nSeems that the cookie value wins before the server value - so if you open some host which sets the store code to A but you have B as cookie value you will be redirected to store B.\r\n\r\nSolution would be to override the cookie value in pub/index.php\r\nif ( isset($_SERVER['MAGE_RUN_TYPE']) == 'store' && isset($_SERVER['MAGE_RUN_CODE']) ) {\r\n    if ( !empty($_SERVER['MAGE_RUN_CODE']) ) {\r\n        $_COOKIE['store'] = $_SERVER['MAGE_RUN_CODE'];\r\n    }\r\n}\r\n$params = $_SERVER;"}}