cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.2.2 store view code redirect to default website

Magento 2.2.2 store view code redirect to default website

Hi, we have a problem configuring a multi website store and store view site.

 

Magento 2.2.2 installed with composer

Ubuntu 16.04

Php 7.1

nginx 1.12

 

Magento use url store code : yes

 

Every store view ha store base url set to the domain (ex. second.store.it) and store base url link setup with {{unsecure_base_url}}

 

We have a this store setup:

 

Default Website > Default Store > Default store view

---->We think to left this default store view for admin purpose.

URL > magento2.store.it

DEFAULT STORE VIEW URL CODE

default -> Italian

 

Second Website > Second Store > n Second store View (one x every language needed).

URL > second.store.it

---->We wont to use this store for sell. 

SECOND STORE URL CODE

sr_it -> Italian

sr_en -> English

sr_es -> Spain

sr_xy -> other language

 

Third Website > Third Store > Third Store View

URL > third.store.it

----> We wont to use this for sell other product

THIRD STORE VIEW URL CODE

it -> Italian

 

We have this virtual server setup:

 

NOTE we have added the $MAGE_RUN_CODE MAGE_RUN_CODE php-fpm map in the virutalhost config because in the nginx.config.sample provided by magento there is no this default config (the magento dev doc for 2.2.2 say "use default magento config nginx.config.sample to pass the value of the variables to php, i think there is an error in the documentation because there is no section in the nginx config sample.)

 

####SECOND.STORE.IT VIRTUALHOST

 

map $http_host $MAGE_RUN_CODE {

hostnames;

   default sr_it;

   second.store.it sr_it;

}

map $request_uri $MAGE_RUN_CODE {

    default   sr_it;

    ~^/sr_en/     sr_en;

}

 server {

listen 80;

add_header mage-run-code $MAGE_RUN_CODE;

server_name second.store.it;

set $MAGE_ROOT /var/www/htdocs/magento2;

#set $MAGE_MODE developer;

#set $MAGE_RUN_TYPE store;

#set $MAGE_RUN_CODE sr_it;

include /var/www/htdocs/magento2/nginx.conf.sample;

        location ~ \.php$ {

        fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

fastcgi_param MAGE_RUN_TYPE store;

}

}

 

#####END SECOND.STORE.IT VIRTUALHOST

 

#####MAGENTO2.STORE.IT VIRTUALHOST

map $http_host $MAGE_RUN_CODE {

hostnames;

#   default default;

   magento2.store.it default;

}

 

server {

listen 80;

add_header mage-run-code $MAGE_RUN_CODE;

server_name magento2.store.it;

   set $MAGE_ROOT /var/www/htdocs/magento2;

 

   #set $MAGE_MODE developer;

   #set $MAGE_RUN_TYPE store;

   set $MAGE_RUN_CODE default;

  

 

   include /var/www/htdocs/magento2/nginx.conf.sample;

 

       location ~ \.php$ {

        fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

fastcgi_param MAGE_RUN_TYPE store;

}

}

####END MAGENTO2.STORE.IT VIRTUALHOST

 

map $http_host $MAGE_RUN_CODE {

hostnames;

   default it;

   third.store.it it;

}

 

server {

listen 80;

 

   add_header mage-run-code $MAGE_RUN_CODE;

 

   server_name third.store.it;

   set $MAGE_ROOT /var/www/htdocs/magento2;

   #set $MAGE_MODE developer;

   #set $MAGE_RUN_TYPE store;

   #set $MAGE_RUN_CODE it;

  

 

   include /var/www/htdocs/magento2/nginx.conf.sample;

 

       location ~ \.php$ {

        fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

fastcgi_param MAGE_RUN_TYPE store;

}

}

####THIRD.STORE.IT VIRTUALHOST

 

 

#####END THIRD.STORE.IT VIRTUALHOST

 

Now the problem is this:

If we call the url

second.store.it/sr_it

or

second.store.it/sr_en

or

we use langauge switcher

all work great.

 

But if we call the url http://second.store.it

Magento redirect (with a 302 moved temp header) to the deafult website, default store view installation so http://magento2.store.it/default/?SID=cre9q00jvmpki7alk7imvljbcr

 

 

####HEADER####

 

Request URL:
http://second.store.it/
Request Method:
GET
Status Code:
302 Found
Remote Address:
46.xxx.xxx.xxx:80
Referrer Policy:
no-referrer-when-downgrade
Response Headersview source
Cache-Control:
max-age=0, must-revalidate, no-cache, no-store
Connection:
keep-alive
Content-Encoding:
gzip
Content-Type:
text/html; charset=UTF-8
Date:
Tue, 13 Feb 2018 17:19:16 GMT
Expires:
Mon, 13 Feb 2017 17:19:16 GMT
Location:
http://magento2.store.it/default/?SID=cre9q00jvmpki7alk7imvljbcr
mage-run-code:
it
Pragma:
no-cache
Server:
nginx/1.12.2
Set-Cookie:
PHPSESSID=cre9q00jvmpki7alk7imvljbcr; expires=Tue, 13-Feb-2018 18:19:16 GMT; Max-Age=3600; path=/; domain=.pineappleitaly.com; HttpOnly
Transfer-Encoding:
chunked
Vary:
Accept-Encoding
X-Content-Type-Options:
nosniff
X-Frame-Options:
SAMEORIGIN
X-XSS-Protection:
1; mode=block
 

So we can see the right url call to second.store.it, a redirect to default website, defautl store view with 302, but the headers mage-run-code show "it" that is the store view code of the third.store.it store view instead "sr_it" that must be the default for second.store.it store view

 

If we try 

http://third.store.it/it all work great, we see third webiste store "it" view.

 

This time if we call http://third.store.it we are redirect to magento2.store.it/default/, header show the "right" mage run code initially asked : "mage-run-code: it"

 
 

Why? 

 

 

 
1 REPLY

Re: Magento 2.2.2 store view code redirect to default website

No one...?