Magento2: 302 redirect loop in multi website/store setup

Created on 4 Jan 2016  路  7Comments  路  Source: magento/magento2

Setting up an multi website with 3 store view (en, de, fr)
is getting 302 redirect loop.

setup:

1 website
1 store
3 storeviews (en, de, fr)

nginx:

# domain.conf

map $http_host $magecode {
hostnames;
default default;
yourdomain.fr fr;
yourdomain.de de;
}

# nginx.conf.sample

fastcgi_param MAGE_RUN_TYPE website;
fastcgi_param MAGE_RUN_CODE $magecode;

after setting the codes, submit the url's in STORES -> CONFIGURATION -> GENERAL -> WEB -> BASE URL per storeview

clear cache and check frontend

your will get a 302 redirect loop

nginx is serving the correct code per domain (MAGE_RUN_CODE) is served

is some situaties my backend got locked as well, it not serving the default url any more.
looking in my network tab of chrome again a 302 loop (a quick workaround of setting up a custom admin url works but not a stable option)

something I also see after comming the FR or DE domain on the storeview level that the last commit URL is located in the website BASE URL (but never commit this)

I tested it on CE and EE

Most helpful comment

"This issue doesn't seem to be magento related, but related to your server settings. Hence, closing this issue. Please feel free to open a new issue if problems arise."

Disagree - we're using your boilerplate .htaccess and nginx vhost configs and we continue to get this undesired behavior.

All 7 comments

@raybogman i can't reproduce the 302 redirect loop. Can you maybe test it with the new release?

@daim2k5 still have redirect loop in nginx and apache setup, using the latest release.

Apache: (here are different setups for apache2)

htacccess

Options +FollowSymLinks
RewriteEngine on

SetEnvIf Host ._mage2cookbook.com._ MAGE_RUN_CODE=default
SetEnvIf Host ._mage2cookbook.com._ MAGE_RUN_TYPE=store

SetEnvIf Host ._mage2cookbook.fr._ MAGE_RUN_CODE=fr
SetEnvIf Host ._mage2cookbook.fr._ MAGE_RUN_TYPE=store

SetEnvIf Host ._mage2cookbook.de._ MAGE_RUN_CODE=de
SetEnvIf Host ._mage2cookbook.de._ MAGE_RUN_TYPE=store

#### pub/index.php

$params = $_SERVER;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'fr';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'de';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';

$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

Nginx:

##### default.conf

map $http_host $magecode {
hostnames;
default base;
mage2cookbook.fr fr;
mage2cookbook.de de;
}

### nginx.conf.sample

location ~ (index|get|static|report|404|503|info).php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;

fastcgi_param MAGE_RUN_TYPE website;
fastcgi_param MAGE_RUN_CODE $magecode;

a little strange
I installed 2 machines with different domain name
I installed both following the magento2 guideline.
one is ok
the other will raise the loop issue when I access the admin page
I google and found this issue could be solved by adding "fastcgi_param HTTPS on;" to /etc/nginx/fastcgi_params

But be carefully, when I add the line to the first "ok" server, it will fail.
I don't know the real issue it's but the problem is still there

the ok server is using AWS China
the bad server is using AWS Oregon

@raybogman @woei66 This issue doesn't seem to be magento related, but related to your server settings. Hence, closing this issue. Please feel free to open a new issue if problems arise.

The solution is to add the following param into /etc/nginx/fastcgi_params if you want setting applied globally, or per VHOST if you want just per host.

fastcgi_param  HTTPS              $https if_not_empty;

It is advised to put this parameter on a global scope of nginx, since it doesn't hurt if you have some stores / sites w/o https, or some which explicitly do use https only as it will be generated on the fly depending on whenever user is visiting http or https site.

"This issue doesn't seem to be magento related, but related to your server settings. Hence, closing this issue. Please feel free to open a new issue if problems arise."

Disagree - we're using your boilerplate .htaccess and nginx vhost configs and we continue to get this undesired behavior.

Was this page helpful?
0 / 5 - 0 ratings