Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different URL keys for different language CMS pages

I'm currently setting up a Magento shop that will support a few different languages.

One issue that I ran into is that I can't find out how to link two CMS pages together, so that when a user switches their language, they are automatically forwarded to the current CMS page but in their preferred language. One option would be to use the same URL key for both pages, but that wouldn't be very user friendly as some users would then see URL keys not in their native language.

Let me give you an example:

I have an "About us" page. In the English version of the store, the URL of that page is /about-us. Now a German user lands on that page and switches his language. But because the German equivalent to "About us" is "Über uns", the German version of that page is at /ueber-uns, so the user would be presented a 404 page because no German version of /about-us exists.

Does anybody know how to solve this issue?

Update: Did some more research and found nothing. I can't believe I am the only one with this problem? The go-to solution, using the same URL key for all languages, seems very ugly and not very user friendly!

like image 713
Louis B. Avatar asked Jun 12 '13 18:06

Louis B.


2 Answers

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

enter image description here

So if a user is using the Francais store view and requests /url-in-english, the redirect will kick in and redirect the user to /url-in-french.

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

like image 182
Louis B. Avatar answered Oct 15 '22 11:10

Louis B.


I have seen this bug in Magento CE 1.8.0.0. The problem here was a wrong assignment in \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php.

To solve this problem it is sufficient to change the assignment of $fromStore in the protected function _rewriteDb() within 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();

with the result that we can access the $stores array with the right key (with the store id instead of the store code). With this the if statement

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

works in the right way.

As a reminder: Do not modify core files. Just copy \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php to \app\code\local\Mage\Core\Model\Url\Rewrite\Request.php before any change. You will find this answer in German here: Rewrite von Seiten in verschiedenen Sprachen und verschiedenen URL Keys in Magento

like image 32
Bastian Kretzschmar Avatar answered Oct 15 '22 13:10

Bastian Kretzschmar