When you use Prestashop in multi-language, addresses / URLs are written as follows:
http://www.boutique-prestashop.com/iso/fichier.php

So this gives:
http://www.boutique-prestashop.com/fr/fichier.php for French.
http://www.boutique-prestashop.com/en/fichier.php for English.
And so on.

We advise you to keep it running, but if you have already listed your shop without the / en / for the French language and you do not want to lose your position on search engines, we offer a solution to change the behavior of Prestashop.
You will therefore have a system to address the following:
http://www.boutique-prestashop.com/fichier.php for French.
http://www.boutique-prestashop.com/en/fichier.php for English.

The change requires changes in system files in Prestashop. A do only if you know what you do! Remember to save all files you edit before.

The following changes:
Link.php in class, look for the method named "getLangLink".
Initially the method ends with this:

Language :: getIsoById return ((int) $ id_lang). '/';

Change like this:

if (:: Save getIsoById ((int) $ id_lang) == 'en')
return ";

Language :: getIsoById return ((int) $ id_lang). '/';

This change will aim to change all the urls used by Prestashop, to delete the subfolder "en".

Frontcontroller.php in class, look for the "init" method
Then try the following code:

/ / If needed langue and language init cookie
if ($ iso = Tools :: getValue ('isolang') AND Validate :: isLanguageIsoCode ($ iso) AND ($ id_lang = (int) (Language :: getIdByIso ($ iso))))
$ _GET ['Id_lang'] = $ id_lang;

Then replace it with:

/ / If needed langue and language init cookie
if ($ iso = Tools :: getValue ('isolang') AND Validate :: isLanguageIsoCode ($ iso) AND ($ id_lang = (int) (Language :: getIdByIso ($ iso))))
$ _GET ['Id_lang'] = $ id_lang;
else
$ _GET ['Id_lang'] = (int) (Language :: getIdByIso ('en'));

To change language, Prestashop used the "en" content in the url. Since there will be more, we explain that if the language is not specified in the url, then the language is French.

Change in your template file header.tpl. Logo level, look for:

<a title="{$shop_name|escape:'htmlall':'UTF-8'}" href="{$base_dir}">

And replace by:

<a href="{$link-> getPageLink ('index.php')} "title =" {$ shop_name | escape: 'htmlall': 'UTF-8'} ">

The purpose of this amendment is simply to always have the correct address based on the language to the index page. By default, for English, the address will http://www.boutique-prestashop.com/ instead of http://www.boutique-prestashop.com/en/

In the file modules / gsitemap / gsitemap.php, searching

foreach ($ langs as $ lang)
$ This-> _addSitemapNode ($ xml, Tools :: getShopDomain (true, true). __PS_BASE_URI__. $ Lang ['iso_code']. '/', '1 .00 ',' Daily ', date (' Ymd '));

And replace by:

foreach ($ langs as $ lang)
if ($ lang ['iso_code'] == 'en')
$ This-> _addSitemapNode ($ xml, Tools :: getShopDomain (true, true). __PS_BASE_URI__, '1 .00 ',' Daily ', date (' Ymd '));
else
$ This-> _addSitemapNode ($ xml, Tools :: getShopDomain (true, true). __PS_BASE_URI__. $ Lang ['iso_code']. '/', '1 .00 ',' Daily ', date (' Ymd '));

The sitemap module writes all urls be followed by the iso at the beginning of the generated file. The goal is to remove the url with the subfolder "en" since it no longer exist.

Finally, open the class Tools.php, find the method generateHtaccess.
Search the following code:

foreach (Meta :: getMetasByIdLang ($ language ['id_lang']) as $ key => $ meta)
if (empty ($ meta ['url_rewrite']) AND Validate :: isLinkRewrite ($ meta ['url_rewrite']))
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/'. $ Meta ['url_rewrite']. '$'] = $ Meta ['page']. '. php? isolang ='. $ language ['iso_code']. ' [QSA, L] ';
elseif (array_key_exists ($ key, $ default_meta) && $ default_meta [$ key] ['url_rewrite']! = ")
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/'. $ Default_meta [$ key] ['url_rewrite']. '$'] = $ Default_meta [$ key] ['page']. '. php? isolang ='. $ language ['iso_code']. ' [QSA, L] ';
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/ ([^? &] *)'] = $ 1? Isolang = '. $ Language [' iso_code '].' [QSA, L] ';

And replace by:

if ($ language ['iso_code'] == 'en') {
foreach (Meta :: getMetasByIdLang ($ language ['id_lang']) as $ key => $ meta)
if (empty ($ meta ['url_rewrite']) AND Validate :: isLinkRewrite ($ meta ['url_rewrite']))
$ Array ['RewriteRule'] ['content'] ['^'. $ Meta ['url_rewrite']. '$'] = $ Meta ['page']. '. Php? Isolang ='. $ Language [' iso_code '].' [QSA, L] ';
elseif (array_key_exists ($ key, $ default_meta) && $ default_meta [$ key] ['url_rewrite']! = ")
$ Array ['RewriteRule'] ['content'] ['^'. Default_meta $ [$ key] ['url_rewrite']. '$'] = $ Default_meta [$ key] ['page']. '. Php? isolang = '. $ language [' iso_code '].' [QSA, L] ';

Else {}
foreach (Meta :: getMetasByIdLang ($ language ['id_lang']) as $ key => $ meta)
if (empty ($ meta ['url_rewrite']) AND Validate :: isLinkRewrite ($ meta ['url_rewrite']))
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/'. $ Meta ['url_rewrite']. '$'] = $ Meta ['page']. '. php? isolang ='. $ language ['iso_code']. ' [QSA, L] ';
elseif (array_key_exists ($ key, $ default_meta) && $ default_meta [$ key] ['url_rewrite']! = ")
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/'. $ Default_meta [$ key] ['url_rewrite']. '$'] = $ Default_meta [$ key] ['page']. '. php? isolang ='. $ language ['iso_code']. ' [QSA, L] ';
$ Array ['RewriteRule'] ['content'] ['^'. $ Language ['iso_code']. '/ ([^? &] *)'] = $ 1? Isolang = '. $ Language [' iso_code '].' [QSA, L] ';
}

Keywords:

, , , , ,

9 comments why not leave yours?

We will not comment for support by a technical problem with one of our modules. Thank you contact us directly with our contact form !

Hello,

Perfect tutorial thank you, but my links EN (only) to the data sheets redirects me to a 404.
The EN version is OK
Ckarone

ckarone March 30, 2012 at 10 h 35 min

Hello,

I just bought via URL Rewriting + adds it without knowing that you were the developers.

My question is: is - it helpful before you install or configure URL Rewriting +, to make a manip at the proposed function by default in 1.4.

On my local installation on wamp, I had a bug due to the activation of the integrated function, or because of htaccess, I have not managed to repair and I had to reinstall everything.

The site is now on the server, but I'd rather ask you to take precautions.

Thank you in advance for your answer, I wait before installing URL Rewriting +.

Cordially.

Jeff February 2, 2012 at 17 h 30 min

hello, I tried to apply this method but I receive the following error message:
Parse error: syntax error, unexpected '$', expecting ']' in / var / www / vhosts / monsite.com / httpdocs / classes / Tools.php on line 1730.
how can I remedied this
thank you

Olive November 27, 2011 at 14 h 28 min

Thank you for this very helpful article, well written, fair and accurate!
Nice work.
Thank you again

beemol November 10, 2011 at 9 am 07 min

Say that the article is intended to help the user set it up in the code saying where to find and how to change it.

If we use the overrides, this does not help really understand what part of the code was referred (or it would have to really detail every step).

In short, this is indeed the best practice to use ;-)

Magavenue 27 June 2011 to 5 h 04 min

Write a comment