How to remove “/en” from URLs in PrestaShop

If you have multiple languages installed in your shop, then all URLs will include language code. And even when you open the home page of your site you’ll get that language suffix, even for default language. It doesn’t look fine but fortunately you can fix this behavior.

This tutorial describes how to remove default language code from your URLs (usually “/en”).

Works for PrestaShop 1.5 / 1.6

You have to use overrides to do this.

  1. Create (or edit if exists) file /override/classes/Link.php
    Paste this code into that file (or merge with existing code):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?php

    class Link extends LinkCore
    {
        protected function getLangLink($id_lang = null, Context $context = null, $id_shop = null)
        {
            $parent_result = parent::getLangLink($id_lang, $context, $id_shop);

            if ($parent_result) {
                if ($id_lang == Configuration::get('PS_LANG_DEFAULT')) {
                    return '';
                } else {
                    return $parent_result;
                }
            }
        }
    }
  2. Create (or edit if exists) file /override/classes/Tools.php
    Paste this code into that file (or merge with existing code):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    <?php

    class Tools extends ToolsCore
    {
        public static function setCookieLanguage($cookie = null)
        {
            parent::setCookieLanguage($cookie);

            if (!$cookie) {
                $cookie = Context::getContext()->cookie;
            }

            if(!Tools::getValue('isolang') && !Tools::getValue('id_lang') && !Tools::isSubmit('id_category_layered')) {
                $cookie->id_lang = Configuration::get('PS_LANG_DEFAULT');
                Context::getContext()->language = new Language($cookie->id_lang);
            }

            /* If language file not present, you must use default language file */
            if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang)) {
                $cookie->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
                Context::getContext()->language = new Language($cookie->id_lang);
            }

            $iso = Language::getIsoById((int)$cookie->id_lang);
            @include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');

            return $iso;
        }
    }

    Note that on line #13 we use Tools::isSubmit(‘id_category_layered’) expression. It helps Blocklayered module to correctly determine the language. You can also add to this line your other modules that have problems with determining language.

  3. Now clear the shop cache (how to clear the cache).

All done! Open your website and check the result.

4 thoughts on “How to remove “/en” from URLs in PrestaShop”

  1. Hi. I tried it, it works in most parts, but once I switch to another language from the ps_languageswitcher module, I cannot return to the default language. PS 1.7.4.2

    1. Hi,
      Sorry, this post was written a long time ago for PrestaShop 1.5/1.6…
      I’ll try to find a solution for PS1.7

Leave a Reply

Your email address will not be published. Required fields are marked *