Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

Wrong redirect with store code in url (when switching language)
Jr. Member
Total Posts:  12
Joined:  2011-06-14

In order to get my users redirected to the store view depending on their browsers language
I activated this Admin Panel → System → Configuration → Web → Url Options → Add store code to Urls → Yes
and added these lines to my .htaccess:

RewriteCond %{HTTP:Accept-Language} ^es [NC]
^$ /es[L,R=301]
# Default Page 
RewriteRule ^$ /en[L,R=301]

When I switch language it doesn’t redirect properly if a category’s url is different in the other language.
For instance, if I am in url:
and switch it to spanish
I get redirected to (404 Error):

When it should be:

What I’ve tried already:
Deactivating .htaccess rules won’t solve.
Looking into getCurrentUrl() ->Gets too deep into the code, can’t follow.

I would appreciate any help.

Someone else is having the same issue here.
Others having similar issues:

EDIT #1:
Using Magento Comunity 1.6.2
EDIT #2:
I’ve just found there is a related bug here, but there’s no info on how to solve it..

Magento Community Magento Community
Magento Community
Magento Community
Jr. Member
Total Posts:  2
Joined:  2011-05-22

Solution (for me):

Modify this file: /app/code/core/Mage/Core/Model/Url/Rewrite.php around line 252, comment line:

// $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();

and substitute with this code:

if (Mage::getStoreConfig('web/url/use_store') && $storeCode Mage::app()->getStore()->getCode()) {
$request->getBaseUrl(). '/' Mage::app()->getStore()->getCode() . '/' $this->getRequestPath(); 
$targetUrl $request->getBaseUrl(). '/' $this->getRequestPath();

Just posting it here for google and in case the source goes 404.

ps: i haven’t added anything to the .htaccess, so you may remove that

Also answered here:

Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top