Running Multiple Magento Stores With Add-on Domains - New Mage::run() parameters don't fit tutorial's expectations

Running Multiple Magento Stores With Add-on Domains - New Mage::run() parameters don't fit tutorial's expectations

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Running Multiple Magento Stores With Add-on Domains - New Mage::run() parameters don't fit tutorial's expectations

Running Multiple Magento Stores With Add-on Domains: Resolving Conflicts Between Tutorials and Default Configurations

Dear developers,

We often encounter situations where we need to set up multiple Magento stores using add-on domains while following tutorials that don’t quite align with the default configurations of our existing installations. This can lead to confusion and unwanted redirections between sites.

Let’s walk through a common scenario involving BroadStore.com as the primary domain and NicheStore.com as an add-on, both pointing to a Magento installation located in /public_html/.

Understanding the Default Magento Index.php Configuration

The default index.php file of your Magento installation likely contains the following code snippet:

/* 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';

Mage::run($mageRunCode, $mageRunType);

This code checks for the presence of MAGE_RUN_CODE and MAGE_RUN_TYPE environment variables in your server configuration. If these are absent, it defaults to running a store.

The Conflict Between Tutorials and Default Configurations

Some tutorials, like this one, suggest replacing the Mage::run() line with something like:

Mage::run('shoes', 'website');

However, this contradicts your current index.php configuration. The tutorial aims to hardcode the store and type directly into your script, which may not be compatible with your existing setup.

A Practical Solution: Using .htaccess and Environment Variables

Instead of modifying the core index.php file, consider using Apache’s .htaccess file in conjunction with environment variables to achieve the desired behavior without touching the Magento codebase.

  1. Add a new .htaccess file: In the root directory of NicheStore.com (usually /public_html/nichestore), create a new .htaccess file with the following content:
SetEnv MAGE_RUN_CODE niche_store_code
SetEnv MAGE_RUN_TYPE website

Replace niche_store_code with the actual code for your second store.

  1. Update your server configuration: Ensure that the environment variables defined in the .htaccess file are included in your Apache configuration for NicheStore.com.

Why This Approach Works

By using environment variables via .htaccess, you avoid modifying the core Magento files while still being able to differentiate between stores and websites based on domain/subdomain. This approach minimizes the risk of breaking updates or core functionality.

Moreover, it allows for a cleaner separation of concerns between your server configuration and your application code, following best practices in maintaining large-scale e-commerce platforms.

Conclusion

When faced with discrepancies between tutorials and default Magento configurations, don’t rush to modify the core files. Instead, leverage Apache’s environment variables and .htaccess files to achieve your goals without compromising the stability of your installation.

Remember, Magento is a complex system designed for scalability and customization. While it may seem daunting at first, understanding its structure allows you to make informed decisions that respect its architecture while serving your business needs effectively.

For more in-depth discussions on Magento configuration and best practices, I highly recommend exploring our comprehensive guides at LaravelCompany.com.

Happy coding!

Checkout Configuration

Our network