Skip to content

Store switch endless loop, wrong navigation block content (wrong store) with multidomain/language setup #3676

Closed

Description

@m-strojek

Steps to reproduce

  1. Install Magento release 2.0.2)
    1a. Disable Fullpage and block cache (just to avoid caching effects)
  2. Setup multistore setup with nginx:
    This setup is meant to handle country domains with a (not unique between stores) language prefix for urls.

E.g.
http://mysite.de/
http://mysite.de/en-DE/
http://mysite.at/
http://mysite.at/en-AT/
http://mysite.ch/
http://mysite.ch/en-CH/

a)
server {
server_name mysite.de

# handle default requests
location ~ (index|get|static|report|console|404|503)\.php$ {

    # set base store for this domain
    fastcgi_param MAGE_RUN_CODE base_de_de;
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;
}
# handle language code requests like mysite.de/en-DE/...
location ~ "\/([a-zA-Z]{2})\-([a-zA-Z]{2})(\/?)(.*)$" {

    fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_de
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;

    include        fastcgi_params;

    # overwrite paths with cleanup of language code
    fastcgi_param  REQUEST_URI $3$4;
}

}

b)

server {
server_name mysite.at

# handle default requests
location ~ (index|get|static|report|console|404|503)\.php$ {

    # set base store for this domain
    fastcgi_param MAGE_RUN_CODE base_de_at;
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;
}
# handle language code requests like mysite.at/de-AT/...
location ~ "\/([a-zA-Z]{2})\-([a-zA-Z]{2})(\/?)(.*)$" {

    fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_at
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;

    include        fastcgi_params;

    # overwrite paths with cleanup of language code
    fastcgi_param  REQUEST_URI $3$4;
}

}

c)
server {
server_name mysite.ch

# handle default requests
location ~ (index|get|static|report|console|404|503)\.php$ {

    # set base store for this domain
    fastcgi_param MAGE_RUN_CODE base_de_ch;
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;
}
# handle language code requests like mysite.at/de-AT/...
location ~ "\/([a-zA-Z]{2})\-([a-zA-Z]{2})(\/?)(.*)$" {

    fastcgi_param MAGE_RUN_CODE base_$1_$2; # will result in e.g. base_en_ch
    fastcgi_param MAGE_RUN_TYPE store;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $MAGE_ROOT/pub/index.php;

    include        fastcgi_params;

    # overwrite paths with cleanup of language code
    fastcgi_param  REQUEST_URI $3$4;
}

}

  1. Store Configuration
    Store 1:
    Name: My Store (Renamed the default)
    Root Category: use default
    Default Store View: DE - DE

Website 1 (Default):

Name: My Website (Renamed the default)
Code: base
Default Store: My Store

Store Views 1:

Name: DE - DE (renamed default)
Code: base_de_de
Backend Base Url: http://mysite.de/
Backend Base Link Url: http://mysite.de/

Store Views 2:

Name: EN - DE
Code: base_en_de
Backend Base Url: http://mysite.de/
Backend Base Link Url: http://mysite.de/en-DE/

Store Views 3:

Name: DE - AT
Code: base_de_at
Backend Base Url: http://mysite.at/
Backend Base Link Url: http://mysite.at/

Store Views 4:

Name: EN - AT
Code: base_en_at
Backend Base Url: http://mysite.at/
Backend Base Link Url: http://mysite.de/en-AT/

Store Views 5:

Name: DE - CH
Code: base_de_ch
Backend Base Url: http://mysite.ch/
Backend Base Link Url: http://mysite.ch/

Store Views 6:

Name: EN - CH
Code: base_en_ch
Backend Base Url: http://mysite.ch/
Backend Base Link Url: http://mysite.de/en-CH/

Expected result

  1. Switching between stores will work as expected
  2. Content will be shown as configured for the store

Actual result

  1. Switching between stores works some time - but at some point you can't get back to the default stores views.
    Additional, at some time endless redirect loops occur between 2 of the stores after switching.
    Can only be fixed by closing browser AND clearing session table AND clearing cache via commandline.
  2. If you call the store with mysite.de you will get
    a) OK a correct store switcher preselection
    b) OK a correct content (some configured cms page)
    c) NOT OK Top Navigation links will show links with a
    language/country prefix and url from the other store (e.g. mysite.ch/en-CH/somecategory.html even if you are on mysite.de.
    Reload of the page will sometimes bring the correct results for the store, sometimes navigation from an other store (wrong too).
    I even checked the context in the navigation block by echo of store id: it's correctly showing the expected store.

Hope that someone has an idea what went wrong here.

Activity

  1. m-strojek commented on Mar 9, 2016

    @m-strojek
    Author

    I figured out a modification which fixes the problem of endless redirects / wrong redirects.
    Seems 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.

    Solution would be to override the cookie value in pub/index.php
    if ( isset($_SERVER['MAGE_RUN_TYPE']) == 'store' && isset($_SERVER['MAGE_RUN_CODE']) ) {
    if ( !empty($_SERVER['MAGE_RUN_CODE']) ) {
    $_COOKIE['store'] = $_SERVER['MAGE_RUN_CODE'];
    }
    }
    $params = $_SERVER;

  2. avra911 commented on May 12, 2016

    @avra911

    Have the same issue on a sub-domain multi stores.
    After using site store switcher on front, is entering in loop in back-end page.

    When browsing the stores, just by typing in the URL, without using the switcher, there is no problem.

  3. rickwhitehead commented on Jun 8, 2016

    @rickwhitehead

    Having the same issue on a simple one website 2 stores site configuration.
    Can be reproduced only if store switcher is used - this sets a 'store' cookie which is not updated correctly when the switcher is used repeatedly and remains set to the initial switch - haven't tried adding another store but suspect it still won't update as expected. Will try to offer a fix suggestion soon.

  4. srbarba commented on Jun 10, 2016

    @srbarba

    Have the same issue, some fix please
    [SOLVED] The problem was the $_COOKIE['store]

  5. GianniPDF commented on Jun 10, 2016

    @GianniPDF

    Looks like m-strojek fix works! Ty

  6. piotrekkaminski commented on Jun 20, 2016

    @piotrekkaminski
    Contributor

    Closing as solution is available above.

  7. gewaechshaus commented on Jul 17, 2016

    @gewaechshaus
  8. ctadlock commented on Jan 4, 2017

    @ctadlock

    @piotrekkaminski Im confused as to why this issue is closed. While the solution that @m-strojek provided works, shouldn't this be added to the Magento code? Why should all of the store owners need to make this fix themselves?

  9. ctadlock commented on Feb 11, 2017

    @ctadlock

    @piotrekkaminski Again, why is this closed?

  10. sabei commented on Apr 25, 2017

    @sabei

    thanks @m-strojek.

  11. sabei commented on Apr 25, 2017

    @sabei

    Why is the solution not added to the core code? Is there any other reason?

  12. maderlock commented on May 17, 2017

    @maderlock

    This "fix" would break the standard store switcher that replies on cookies overriding server settings. The standard approach is for the server to set a default store, and then your cookie determines whether a different store is used. So adding this to the core code might solve your situation, but it would break other people's sites, so it's unlikely to be done.

  13. added a commit that references this issue on Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions