Setting Up Multistore Domains in Magento: How to Prevent Automatic Redirection
Multistores are an essential feature for Magento e-commerce platforms that need to cater to multiple regions or languages. However, setting up the domain configuration can sometimes lead to unexpected redirects between your stores.
Understanding the Domain Redirect Issue
You’re currently facing a common challenge when configuring multistore domains in Magento. Despite having separate vhost entries and distinct server aliases for mainfr.devsite.com and main.devsite.com, Magento is automatically redirecting all traffic from the French store to the main store domain.
This redirection occurs due to the way Magento handles the mage::run() function, which is called in your index.php file. When this function executes, it checks the server name against a predefined condition ($serverName[0] == "mainfr"), and if true, it runs the French store ("fr", "website"). If false, it defaults to running the main store.
Why Magento Redirects
The automatic redirect is a built-in feature of Magento designed for security purposes. It ensures that users cannot access non-existent or incorrectly configured stores, preventing potential errors and maintaining site stability.
However, in your specific setup, this feature is causing an unwanted behaviorâit’s forcing all mainfr.devsite.com traffic to the main.devsite.com domain.
Stopping the Magento Redirect
To prevent the automatic redirection from occurring, you can follow these steps:
1. Configure Magento URL Settings
- Log in to your Magento admin panel.
- Navigate to System > Configuration (under the ‘Advanced’ menu).
- Click on Web.
- Under Base URLs, ensure that both the main domain and French domain are set correctly.
Here’s an example of how the settings should look:
Unsecure Base URL: http://main.devsite.com
Secure Base URL: https://main.devsite.com
French Store:
Unsecure Base URL: http://mainfr.devsite.com
Secure Base URL: https://mainfr.devsite.com
2. Update the Vhost Configuration
Ensure that your vhost configuration is set up correctly for both domains:
- The main domain (e.g.,
main.devsite.com) should have a corresponding base URL in Magento. - The French domain alias (
mainfr.devsite.com) should be configured to point directly to the French store’s folder without redirecting.
3. Check Your Rewrite Rules
Ensure that your .htaccess rewrite rules are not causing any conflicts or unintended redirects. In a clean Magento installation, the default rules should work correctly with multistore domains.
Best Practices for Multistore Domain Setup
To prevent such issues in the future:
- Always use unique and clearly defined domain names for each store.
- Ensure that your vhost configuration matches the Magento URL settings exactly.
- Avoid using complex or nested subdomains if possible, as they can lead to more complicated setup requirements.
Conclusion
Setting up multistores in Magento requires a careful balance of server configuration and Magento core settings. By following the steps outlined aboveâensuring correct URL configurations, updating vhost files, and checking rewrite rulesâyou should be able to stop the automatic redirection between your domains.
Remember, while Magento’s built-in redirect is designed for security, it can sometimes conflict with specific domain setups. Always ensure that your server configuration matches your intended Magento behavior.
For more detailed guides on Magento multistore setup and best practices, feel free to explore our comprehensive tutorials at Laravel Company.