Manu-41 Posted January 5, 2023 Share Posted January 5, 2023 (edited) 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 January 16, 2023 by Manu-41 ok (see edit history) Link to comment Share on other sites More sharing options...
Manu-41 Posted January 5, 2023 Author Share Posted January 5, 2023 (edited) 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 January 5, 2023 by Manu-41 er (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted January 5, 2023 Share Posted January 5, 2023 Bonjour, pourquoi considérez-vous que cela est un problème ? Link to comment Share on other sites More sharing options...
Manu-41 Posted January 5, 2023 Author Share Posted January 5, 2023 (edited) Apparemment, cela pose un souci pour le seo. J'ai regardé sur plusieurs sites prestashop, et sur la 2 ème page, l'URL canonique est bien l'URL de la page originale. Mais je ne trouve pas le problème est ce un souci de pagination ? Edited January 5, 2023 by Manu-41 Pafination (see edit history) Link to comment Share on other sites More sharing options...
Manu-41 Posted January 16, 2023 Author Share Posted January 16, 2023 (edited) 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 January 16, 2023 by Manu-41 f (see edit history) 1 Link to comment Share on other sites More sharing options...
Manu-41 Posted January 16, 2023 Author Share Posted January 16, 2023 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 More sharing options...
Manu-41 Posted January 16, 2023 Author Share Posted January 16, 2023 Allez, soyons fous, pour les pages CMS, le très bon tuto de Mediacom https://www.mediacom87.fr/prestashop-17-ajouter-lurl-canonique-aux-pages-cms/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now