Jump to content

Résolu - Probleme balise canonical


Recommended Posts

Bonjour, je rencontre un souci avec la balise canonical

Sur une page 2 d'une catégorie, la balise indique

monsite/lettre-158?page=2

Au lieu de : monsite/lettre-158

Voici le code que j'ai dans le head sous ps 1.7.8.2

{if $page.canonical}
    <link rel="canonical" href="{$page.canonical}">
  {/if}

Auriez-vous une idée pour régler le problème ?

Merci

 

Edited by Manu-41
ok (see edit history)
Link to comment
Share on other sites

dans le CategorieControler.php j'ai ce code:

    public function canonicalRedirection($canonicalURL = '')
    {
        if (Validate::isLoadedObject($this->category)) {
            parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
        }
    }

    public function getCanonicalURL()
    {
        if (!Validate::isLoadedObject($this->category)) {
            return '';
        }
        $canonicalUrl = $this->context->link->getCategoryLink($this->category);
        $parsedUrl = parse_url($canonicalUrl);
        if (isset($parsedUrl['query'])) {
            parse_str($parsedUrl['query'], $params);
        } else {
            $params = [];
        }
        $page = (int) Tools::getValue('page');
        if ($page > 1) {
            $params['page'] = $page;
        } else {
            unset($params['page']);
        }
        $canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]);

        return $canonicalUrl;
    }

 

Edited by Manu-41
er (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

J'ai trouvé.

Pour ceux que cela intéressé pour la balise canonical des pages catégories

le chemin : /controllers/front/listing/CategoryController

remplacez

$page = (int) Tools::getValue('page');
        if ($page > 1) {
            $params['page'] = $page;
        } else {
            unset($params['page']);
        }
        $canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]);

par

$page = (int) Tools::getValue('page');
        
            unset($params['page']);
      
        $canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]);

Ça fonctionne chez moi ps 1.7.8.2

Edited by Manu-41
f (see edit history)
  • Like 1
Link to comment
Share on other sites

Aussi, pour les pages manufacturer:

dans le même répertoire, mais fichier ManufacturerController

à la ligne 177 (environ) ajouter

public function getCanonicalURL()
    {
        if ($id_manufacturer = Tools::getValue('id_manufacturer')) {
            return $this->context->link->getManufacturerLink($this->manufacturer);
        }
    }

 

Link to comment
Share on other sites

  • Manu-41 changed the title to Résolu - Probleme balise canonical

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...