- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Multistore under localhost keep redirect to main store
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:

$params[\Magento\Store\Model\StoreManager:

}else{
$params[\Magento\Store\Model\StoreManager:

$params[\Magento\Store\Model\StoreManager:

}
$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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Multistore under localhost keep redirect to main store
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Multistore under localhost keep redirect to main store
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Multistore under localhost keep redirect to main store
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Multistore under localhost keep redirect to main store
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.