How Should I Implement Canonical Urls In My Prestashop Theme?

- 1 answer

canonical urls are currently activated on the shop, but the won't be written in frontend source code. So I took a look even to the default-bootsrap theme, the last from github, but it seems it doesn't implement any canonical url.

I also checked all the controllers, but it seems no one sets a $canonical_url (something like..) smarty var, so what the hell is the related backoffice option?

I searched the web but found nothing really useful.



The backoffice option Canonical url is only used in controllers.

If you have activated the url rewriting option and try to access this link:

You will be redirected to, for example:

Here is an extract from the canonicalRedirection method from FrontController class:

 * Redirects to canonical URL
 * @param string $canonical_url
protected function canonicalRedirection($canonical_url = '')

    $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302';
    header('HTTP/1.0 '.$redirect_type.' Moved');
    header('Cache-Control: no-cache');

In this method we get the canonical redirect option you selected in the BackOffice with this line Configuration::get('PS_CANONICAL_REDIRECT').

If you want canonical url in your html header you'll have to write or get a module for that as it is not included in Prestashop.