Different URL keys for different CMS language pages

I am currently creating a Magento store that will support several different languages.

One of the problems I encountered is that I cannot learn how to link two CMS pages together, so when a user switches their language, they are automatically redirected to the current CMS page, but in their preferred language. One option is to use the same URL for both pages, but this is not very convenient, as some users will not see URL keys in their native language.

Let me give an example:

I have a page about us. In the English version of the store, the URL of this page is /about-us . Now the German user lands on this page and switches his language. But since the German equivalent of "About Us" is "Über uns", the German version of this page is on /ueber-uns , so the page 404 will be presented to the user because the German version of /about-us does not exist.

Does anyone know how to solve this problem?

Update . A few more studies and found nothing. Can't believe I'm the only one with this problem? A solution using the same URL key for all languages ​​seems very ugly and not very user friendly!

+6
source share
3 answers

So, the only solution I found was to manually create a redirect for each page in the Magento rewrite rules. Do this, go to Catalog -> URL Rewrite Management and add each page in the following format:

enter image description here

So, if a user uses the Francais store view and asks for /url-in-english , the redirect will go in and redirect the user to /url-in-french .

This, of course, is not an ideal solution, it would be desirable if the two pages could be "linked" directly, but I believe that I will have to use this at the moment. If anyone comes up with a better solution, feel free to add yours!

+8
source

I saw this error in Magento CE 1.8.0.0. The problem here was the wrong assignment in \ app \ code \ core \ Mage \ Core \ Model \ Url \ Rewrite \ Request.php.

To solve this problem, just change the purpose of $ fromStore in the protected _rewriteDb () function in the Mage_Core_Model_Url_Rewrite_Request class from

 $fromStore = $this->_request->getQuery('___from_store'); 

to

 $fromStore = Mage::getModel('core/store')->load($this->_request->getQuery('___from_store'), 'code')->getId(); 

as a result, we can access the $ stores array with the right key (with the store ID instead of the store code). Moreover, the if statement

  if (!empty($stores[$fromStore])) { 

works correctly.

As a reminder: do not modify the kernel files. Just copy \ app \ code \ core \ Mage \ Core \ Model \ Url \ Rewrite \ Request.php \ app \ code \ local \ Mage \ Core \ Model \ Url \ Rewrite \ Request.php before any changes. You will find this answer in German here: Rewrite von Seiten in verschiedenen Sprachen und verschiedenen URLs in Magento

+2
source

The above solution works, but it takes some time. We just did the following to rewrite the language change URL when on the cms page go to the base URL:

Add the following code to app/design/frontend/default/template_name/template/page/switch/languages.html after the part where the variable $ url is filled (in ours it was like

 $url = /*explode( '?',*/$_lang->getCurrentUrl()/*);*/; 

so we added the following:

 if(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.com/')){$url = strstr($url, '.com/', true) . '.com/';} elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.de/')){$url = strstr($url, '.de/', true) . '.de/';} elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.nl/')){$url = strstr($url, '.nl/', true) . '.nl/';} 

What I did here is to check if the cms page is on and check if the URL contains .com / ;. de / or .nl and split the part and then add the domain extension back.

in our example: http://www.mega-watch.com/about-us?blabla will become http://www.mega-watch.com/

Hope this helps someone ...

+1
source

Source: https://habr.com/ru/post/947149/


All Articles