Mark
Mark

Reputation: 632

Multiple Magento 1.9 Websites/Stores on same domain

I need to create separate retail and wholesale stores and plan to do this on the same domain using the URL structure mysite.com/store and my site.com/wholesale.

I have created separate websites in the Magento backend and entered the relevant unsecure/secure base urls. mysite.com/store is working great and showing all products etc... however if I go to mysite.com/wholesale i just get a standard server 404 (as opposed to the Magento 404).

How do I set this up correctly? Do I need a 'wholesale' folder in my root directory or make changes to the .htaccess in the Magento root or something similar?

Every tutorial or question on SO or magento.stackexchange seem to be based on separate stores on different domains / subdomains.

Upvotes: 1

Views: 3816

Answers (3)

Andreas Koch
Andreas Koch

Reputation: 2037

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.

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

screenshot: magento "add store-code to url"-option

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 showing the steps of adding the Magento store-code to the URL

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';
php_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 almost no changes from the default index.php except two locations

  • You must tell Magento where its real root is: define('MAGENTO_ROOT', dirname(getcwd()));
  • And you must specify the store code: Mage::run('wholesale', 'store');

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.

Upvotes: 3

user439441
user439441

Reputation:

The problem is that when you go to mysite.com/wholesale, the Apache web server thinks it's a directory. That's why you get a 404 instead of a Magento generated. Do you have the standard Magento .htaccess in the root of the Magento website?

Upvotes: 0

Jacob
Jacob

Reputation: 1

What webserver are you using you could fix this with a simple nginx configuration.

Upvotes: 0

Related Questions