Magento: Separating multiple stores under the same domain using store folder

In order to use separate folders for different stores under the same domain name you can use the relativly new "Add Store Code to Urls"-option or by using a customized index.php
created by on 2015-07-03

You can find this option under System > Configuration > Web > Url Options. The core_config path is web/url/use_store.

Screenshot: Magento Backend » System Configuration »  Web Url Options » Add Store Code to  Urls

To make use of this option you should

  1. use the same base-url for the stores (no need to add the /wholesale folder to the base url)
  2. Set the store code to the same name you would like to have as a subfolder of your base url (e.g. “wholesale”)

Animation: Configure multiple shops on the same domain in Magento

This works independent of the web server you are using. So no change to any .htaccess files required.

If you want to name the website folder something different than your store code you will have to create the folder and add a custom index.php to it that sets the correct store code:

<?php
/**
 * Error reporting
 */
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    error_reporting(E_ALL | E_STRICT);
    ini_set("display_errors", 1);
    ini_set("log_errors", 1);
} else {
    error_reporting(E_ERROR);
    ini_set("display_errors", 0);
    ini_set("log_errors", 1);
}

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', dirname(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;

/**
 * Enable developer mode
 */
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}
umask(0);

Mage::run('wholesale', 'store');

There are no changes from the default index.php except two locations

All other lines are standard Magento.

Theoretically you should also be able to accomplish the same with rewrite rules, but I have never got this to work properly.

Note: This information is not particularly interesting but I took the time to write this down as an answer to a question on stackoverflow in April. But the person asking lost interest in his question and did not accept or comment the answer. So I am posting it here …

Tags: