3
votes

I have two stores within a single installation of Magento, and I have a separate domain for the second store that just points to the main installation (there are no files in the second domain at all). However, the second store isn't loaded when the user visits through the second domain, the categories and products of the default store are loaded. I added the following lines to the .htaccess file in Magentos' root but they doesn't seem to be working.

############################################
enable rewrites

SetEnvIf Host www\.testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host www\.testsite\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host ^testsite\.com MAGE_RUN_TYPE=website

Options +FollowSymLinks
RewriteEngine on
############################################

shoe_store is the code for the 'Website Name' of the second store, not the 'Store View Name' but neither of them work. I'm not sure what all the back slashes are for but they are in all the tutorials I've read. I've also checked the Base URL in both the Secure and Unsecure sections and it's the correct address with a / at the end (http://testsite.com/).

I've got multiple stores working with sub-domains but separate domains is proving more difficult. Anyone know what I'm doing wrong?

Edit: Added in the index.php code below

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL | E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

if (file_exists($autoload = __DIR__.'/vendor/autoload.php')) {
    require_once $autoload;
}

switch($_SERVER['HTTP_HOST']) {
     case 'mainsite.com':
     case 'www.mainsite.com':
          $mageRunCode = 'base'; //not your website code, it should be code for your first store
          $mageRunType = 'website'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
           break;
     case 'testsite.com':
     case 'www.testsite.com':
           $mageRunCode = 'shoe_store'; //code of second store
           $mageRunType = 'website';
           break;
}
Mage::run($mageRunCode, $mageRunType);
1
you have to specify root category for the store.MeenakshiSundaram R
Hi, I have two root categories for each store, and for Store View in the 'Manage Stores' section I've specified 'Shoe Store' as the root category and not 'Default Category', do I need to do it anywhere else?thekingsrook
have you clear the cache?MeenakshiSundaram R
I have the cache disabled for now,and I reindexed the data but it's still the main store view that's coming up.thekingsrook
could you show by index.php for second storeMeenakshiSundaram R

1 Answers

1
votes

By going through your issue, I feel that your domains are working perfectly. However for your two domains same store (default one) is loading. This is because you didn't specify that which store to load for which domain. For magento, your two domains are strangers and hence it will load with default store for each one.

So we want to inform magento that, for each of domain, a particular store should load. Store is loading in index.php itself (in root directory.).

Please go to index.php file and you will see the last line that loads the desires store and store view. We need to alter it some how so that magento should load the correct store according to our need.

So add the following code just above this code snippet Mage::run($mageRunCode, $mageRunType);

 switch($_SERVER['HTTP_HOST']) {
     case 'firstdomain.com':
     case 'www.firstdomain.com':
          $mageRunCode = 'store_code'; //not your website code, it should be code for your first store
          $mageRunType = 'store'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
           break;
     case 'seconddomain.com':
     case 'www.seconddomain.com':
           $mageRunCode = 'store_code'; //code of second store
           $mageRunType = 'store';
           break;
}
Mage::run($mageRunCode, $mageRunType);

Hope that helps...