Multiple Websites ( Separate Domains) on single Magento Instance (Problem: New Domain , routing to first website instead of new website )
-
09-03-2021 - |
Question
I am working on a Magento 2.2.7 running on Apache/Linux/Cloudways. Before I started working here, three websites were already setup to run on a single magento instance. Microbattery.com , HearingAidBatteryShop.com, and cochlearbatteries.com. I am now trying to add a third site using the magento backend. I created the website, store and storeview for hearing-aid-batteries.com and its pointed to our servers. I modified the rewrites in the .htaccess file of my magento directory but hearing-aid-batteries.com is redirecting to microbattery.com for some reason.
I have tried the following: php bin/magento cache:clean
php bin/magento cache:flush
rm -rf var/cache/*
php bin/magento reindexer:index
I checked the tmp director to see if any cache files were being stored in there.
I changed the base url for hearing-aid-batteries.com to http://hearing-aid-batteries.com
All of these things still result in the same issue.
hearing-aid-batteries.com redirects to microbattery.com
.htaccess and sitemap config
SetEnvIf Host wwww\.hearing-aid-batteries\.com MAGE_RUN_CODE=habaffiliate
SetEnvIf Host staging\.hearing-aid-batteries\.com MAGE_RUN_CODE=habaffiliate
SetEnvIf Host www\.hearing-aid-batteries\.com MAGE_RUN_TYPE=website
setEnvIf Host staging.\hearing-aid-batteries\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^hearing-aid-batteries\.com MAGE_RUN_CODE=habaffiliate
SetEnvIf Host ^hearing-aid-batteries\.com MAGE_RUN_TYPE=website
RewriteCond %{HTTP_HOST} ^.*hearing-aid-batteries\.com$
RewriteRule ^sitemap.xml$ /aff/sitemap.xml [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^hearing-aid-batteries.com [NC]
RewriteRule ^(.*)$ https://www.hearing-aid-batteries.com/$1 [L,R=301,NC]
Solution 2
turns out the error was a simple typo. if you look at my initial post:
I typed : SetEnvIf Host wwww.hearing-aid-batteries.com MAGE_RUN_CODE=habaffiliate
there is an extra
w
in the url which caused cloudways to auto redirect to the main site since there was no redirect found for the actual url : www.hearing-aid-batteries.com (with 3 w's )
OTHER TIPS
Have you considered editing index.php
Similar to what's shown in this example
https://magento.stackexchange.com/a/183980/70343
It worked for us on a problem install