cancel
Showing results for 
Search instead for 
Did you mean: 

Multistore under localhost keep redirect to main store

Multistore under localhost keep redirect to main store

Hi everybody,
I recently inherited a magento westore that is configured with two store. In production everything is working fine with two different domain. I tried to make it work in local but I am having some trouble to open the second store that actually loads the main store.
 
I cannot use the hosts file to create some mock domain and redirect them to localhost because I have to find a solution that will work also on my test environment, where the client will to access true the server ip and I cannot ask them to modify the hosts file, unfortunately I even don't have a domain to use for the test env at the moment.
 
Because of this reason I have two virtualhosts on two different ports. Configured in this way:
Listen 80
<VIRTUALHOST>
ServerAdmin admin@localhost
ServerName app
#ServerAlias www.app

SetEnv FIRST_STORE true

DocumentRoot /var/www/app

<DIRECTORY>
Options Indexes FollowSymLinks
AllowOverride All
AddDefaultCharset utf-8
Require all granted
</DIRECTORY>
</VIRTUALHOST>

Listen 81
<VIRTUALHOST>
ServerAdmin admin@localhost
ServerName app
#ServerAlias www.app

SetEnv FIRST_STORE false

DocumentRoot /var/www/app

<DIRECTORY>
Options Indexes FollowSymLinks
AllowOverride All
AddDefaultCharset utf-8
Require all granted
</DIRECTORY>
</VIRTUALHOST>
and I added in the index.php this lines:
$isFirst = apache_getenv ( "FIRST_STORE");

$params = $_SERVER;
if($isFirst == 'true'){
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_CODE] = 'first';
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_TYPE] = 'website';
}else{
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_CODE] = 'second';
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_TYPE] = 'store';
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
Despite of this configuration the second store is not loading. Where am I wrong and how can i solve this issue?

Thanks to everybody who will help me.
8 REPLIES 8

Re: Multistore under localhost keep redirect to main store

@LikeGrees As you have created two virtual hosts then just go the admin->store-configuration->general->web and then from the Store View configuration select the website and change the base url and check if it works.

 

Thanks

Re: Multistore under localhost keep redirect to main store

Thanks Rahul Gupta, I forgot to mention that this settings were already updated, indeed I am not redirect to the first store just the second loads the assets of the first.
But I noticed a difference between the two stores the main website works perfectly and every assets is in the place, the second one is loading the asstes of the first but some icon are missing. Maybe this can help to identify the problem.

Re: Multistore under localhost keep redirect to main store

@LikeGrees can you please check if you find any error on browser console.

 

Thanks

Re: Multistore under localhost keep redirect to main store

Hello @LikeGrees 

 

Are you using 1 store url for media and skin files, if yes then update with second store url.

 

Hope it will help you.

 

If works then mark as solution.

 

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Multistore under localhost keep redirect to main store

No errors. What I don't understand is why it try to load everything from the first store... The link to the CSS files, logos and images are the same of the first store.

Re: Multistore under localhost keep redirect to main store

I think this is the problem. But can you explain how to update with the second store URL? Thanks

Re: Multistore under localhost keep redirect to main store

Hello @LikeGrees 

 

go to backend 

 

Stores >> Configuration >> General >> Web

 

From left top side select your site and check your url and update based on that.

 

Hope it will help you.

 

if works then mark as solution


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Multistore under localhost keep redirect to main store

Sorry but I already answered to Rahul that this configuration was already updated. Still that from the html page all the links to the assets are pointing to the first store.