Magento keeps redirecting to default website for a multisite store

Magento keeps redirecting to default website for a multisite store

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento keeps redirecting to default website for a multisite store

Troubleshooting Multisite Magento Redirection Issues on Local Development

When working with multi-site Magento installations, you may encounter redirection issues during local development. This is particularly common when switching between different websites within your setup. I’ll guide you through a step-by-step process to resolve this issue effectively.

Understanding the Environment Setup

You’ve done an excellent job setting up your environment:

  1. Code Download: You’ve successfully downloaded the code from your live site.
  2. Virtual Host Configuration: Your Apache virtual hosts are configured correctly for each of the three websites (site1.com, site2.com, and site3.com).
  3. Hosts File Update: The /etc/hosts file is updated with the corresponding IP address mappings.
  4. .htaccess Configuration: You’ve implemented the necessary .htaccess directives to manage redirection between the sites.

Identifying the Root Cause

The redirection issue you’re facing is likely due to the default website setting in your local environment not being configured correctly. Here’s what’s happening:

  • By default, Magento looks for a MAGE_RUN_CODE and MAGE_RUN_TYPE environment variable to determine which site to load.
  • If these variables are not set or misconfigured, Magento falls back to the default website setting in your database.

Troubleshooting Steps

To resolve this issue:

Step 1: Verify Your Database Configuration

Log into MySQL as a user with access to your Magento database. Navigate to the core_config_data table and look for the following records:

  • path/config/website/default
  • path/config/website/default_group

Ensure these values are set correctly based on your local environment setup.

Step 2: Check Your Apache Configuration

Verify that your virtual host files (site1.com.conf, site2.com.conf, and so forth) have the following lines configured:

<VirtualHost *:80>
    ServerName www.site1.com
    DocumentRoot /var/www/magento/site1

    <Directory /var/www/magento/site1/>
        Options -Indexes +Includes +FollowSymLinks
        DirectoryIndex index.php
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

    SetEnv MAGE_RUN_CODE site1
    SetEnv MAGE_RUN_TYPE website

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (!^/(media|skin|js)) [NC]
        RewriteRule .* index.php [L]
    </IfModule>

</VirtualHost>

Make sure the SetEnv lines are present and correctly configured for each website.

Step 3: Review Your .htaccess File

Ensure your .htaccess file is structured as follows:

RewriteEngine on
RewriteBase /

# Set environment variables to run specific store
SetEnvIf Host ^www\.site1\.com MAGE_RUN_CODE=site1
SetEnvIf Host ^www\.site1\.com MAGE_RUN_TYPE=website

SetEnvIf Host ^www\.site2\.com MAGE_RUN_CODE=site2
SetEnvIf Host ^www\.site2\.com MAGE_RUN_TYPE=website

# Add other websites here as needed

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

The RewriteBase directive ensures that relative URLs work correctly. The SetEnvIf directives should match the hostnames of your virtual hosts exactly.

Best Practices for Multisite Development

To avoid such issues in the future:

  1. Use a Separate Database: Always use separate databases for each website, especially during local development.
  2. Configure Environment Variables: Set the MAGE_RUN_CODE and MAGE_RUN_TYPE environment variables correctly for your local setup.

Conclusion

By following these steps and double-checking your configuration files, you should be able to resolve the multisite redirection issue on your local machine. Remember that careful attention to virtual host settings and environment variables is key when working with multi-site Magento installations.

If you’re looking for more in-depth guides and best practices for Magento development and deployment, I recommend checking out our comprehensive resources at Laravel Company. We offer a range of tutorials and tools designed to help developers like yourself master the Magento platform effectively.

Database Configuration Errors

Our network