Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Multi website configuration using $_SERVER[’SERVER_NAME’] in index.php
 
aximus
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-09-03
Netherlands
 

Hi guys,

I’m testing a multi-website configuration (1.1.7). Since i can’t modify the vhost settings (required so website a can access website b’s files), I’ve tried setting it up using $_SERVER[’SERVER_NAME’]. My index.php looks somewhat like this:

if($_SERVER['SERVER_NAME'== 'www.domain-a.com'Mage::run('website-a''website');
elseif(
$_SERVER['SERVER_NAME'== 'www.domain-b.com'Mage::run('website-b''website');
else 
Mage::run('website-global''website'); //www.domain-global.com

I’ve set up the stores (admin panel -> system -> manage stores) and did the website configuration (admin panel -> system-> configuration -> web). Nothing new here, everything works fine.

But here’s my first question: are there any known issues regarding my approach, using $_SERVER[’SERVER_NAME’] to determine what website to run?

My second question is regarding the catalog. I have one root catalog that basically belongs to domain-global.com. In domain-a and domain-b i only want to use part of the catalog so i disabled some categories for those websites. Now the problem is that the URL’s in the frontend of website-a and website-b, link to website-global’s domain. So as soon as i click a category at www.domain-a.com or www.domain-b.com, I end up at that category at www.domain-global.com. It does not change the store though, only the domainname in the URL. The other links, like account, wishlist, etc, work fine (remain the same domain name).

Is this because of my approach using $_SERVER[’SERVER_NAME’], or is there something else i’m doing wrong? A possible solution is creating 3 root catalogs. But that might create inconsistency in the catalogs.

Any help in the right direction is much appreciated!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Crucial
Enthusiast
 
Avatar
Total Posts:  770
Joined:  2007-11-07
Phoenix, AZ
 

Use something like this:

switch($_SERVER['HTTP_HOST']{
    
case 'domain.com':
    case 
'www.domain.com':
        
Mage::run('STORE_CODE_HERE''website');
    break;
    default:
        
Mage::run();
    break;
}

See the following for full instructions:

http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/

 
Magento Community Magento Community
Magento Community
Magento Community
 
aximus
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-09-03
Netherlands
 

A switch is indeed more elegant then then the if - elseif construction i came up with. Thanks for your help.

I’m wondering tho if this has any impact on the speed?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Crucial
Enthusiast
 
Avatar
Total Posts:  770
Joined:  2007-11-07
Phoenix, AZ
 

I doubt it, we’d be talking, if anything, milliseconds. The important part would be the actual variable though:

$_SERVER['SERVER_NAME']

...compared to:

$_SERVER['HTTP_HOST']

I prefer if-else statements myself, and would probably do something like:

if(preg_match('/^(www\.)?domain\.com$/'$_SERVER['HTTP_HOST'])) {
    Mage
::run('STORE_CODE''website');
else {
    Mage
::run();
}

If you’re really concerned though, switch out the $_SERVER variable with a known variable instead, like:

$host 'www.domain.com';

And try all three methods, the if-else (yours and mine), and the switch. Put a start and stop timer on it and have it run 100 times through. Or do an AB test on it via SSH. But again, the differences would be negligible, and the switch method is how Varien does it.

Sorry I can’t help with the other question, my experience is more on the technical side of things, not so much the working aspect of Magento hmmm

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top