Removing Store Code for Default Store Views in Magento
In Magento, by default, all store views have their unique codes appended to URLs for easy navigation between stores. However, there are cases where you might want to remove the store code from the URL of your default store view, especially for SEO purposes or for a cleaner URL structure.
Current Scenario and Requirements
You currently have two store views - French and Dutch, with French being the default one. To optimize your URLs for better crawlability, you’d like to achieve the following:
- French Store View (Default):
http://www.domain.com/category/product - Dutch Store View:
http://www.domain.com/nl/category/product
The built-in Magento setting System -> Configuration -> Web -> Add Store Codes to URL is an all-or-nothing switch, applying to all store views simultaneously.
Step-by-Step Solution
1. Understanding the Default Store View
In your default French store view, you’ll notice that the store_code in the Magento configuration doesn’t directly influence the URLs when this setting is enabled for all stores. The URL generation logic actually checks if a store is set as the default.
2. Editing the Configuration XML
To remove the store code from the URL of your default store view, you’ll need to edit the app/etc/config.xml file. This file contains the core configuration settings for Magento.
Here’s how you can do this:
- Open the
config.xmlfile in a text editor. - Locate the
<default>node within the<stores>section. - Find the
<url>child element and ensure it looks like this for your default store view:
<url>
<base>http://www.domain.com/</base>
<secure_base>https://www.domain.com/</secure_base>
<unsecure_base>http://www.domain.com/</unsecure_base>
</url>
- Save and close the file.
3. Clearing the Cache
After updating the config.xml file, you’ll need to clear Magento’s cache:
- Navigate to System -> Cache Management in your admin panel.
- Select all the cache types that are enabled.
- Click on the Flush Cache Magically button.
Verifying the Changes
Once you’ve completed these steps and flushed the cache, visit your website’s homepage or a category page. You should now see that the French store view URLs have no store code appended:
http://www.domain.com/category/product
While this solution is effective for removing the store code from the default store URL view, remember to exercise caution when directly editing core Magento files like config.xml. Always backup your site and test changes thoroughly in a staging environment before applying them to production.
For more detailed information on Magento’s URL generation logic and advanced configuration options, I recommend checking out Laravel Company’s comprehensive guides for a deeper dive into this topic.