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 magento.stackexchange.com, 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 community@magento.com.

Magento Forum

Wrong redirect with store code in url (when switching language)
 
syscoel
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]
RewriteRule 
^$ /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:
http://www.mysite.com/en/brands/brand1/receivers.html
and switch it to spanish
I get redirected to (404 Error):
http://www.mysite.com/marcas/marca1/receptores.html

When it should be:
http://www.mysite.com/es/marcas/marca1/receptores.html

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:
http://stackoverflow.com/questions/9096622/magento-multilanguage-double-change-in-language-resuts-in-404-or-how-to-chang
http://stackoverflow.com/questions/7322121/404-error-when-switching-between-stores-when-in-a-category-on-magento

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
 
rj8webdesign
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()) {
     $targetUrl 
$request->getBaseUrl(). '/' Mage::app()->getStore()->getCode() . '/' $this->getRequestPath(); 
else
     
$targetUrl $request->getBaseUrl(). '/' $this->getRequestPath();

Source: http://samuiweb.net/magento-store-code-url-bug/
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: http://www.magentocommerce.com/boards/viewthread/287883/

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