How Should I Implement Canonical Urls In My Prestashop Theme?
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.
Answer
The backoffice option Canonical url is only used in controllers.
If you have activated the url rewriting option and try to access this link:
http://dev.test.com/index.php?id_product=1&controller=product
You will be redirected to, for example:
http://dev.test.com/tshirts/1-T-shirts-a-manches-courtes-delaves.html
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');
Tools::redirectLink($final_url);
}
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.
Related Questions
- → How do I call the value from another backed page form and use it on a component in OctoberCms
- → Inline JS callback syntax Vs Internal JS callback syntax
- → Prevent form action from being followed by robots
- → How to remove parameters from the root URL if it does I18n
- → SEO Canonical URL in Greek characters
- → Htaccess negation
- → Wrapping anchor elements with text
- → Adding schema.org to site
- → dynamic php title depends on page id and using of "if (isset"
- → Building sitemap for 2 wordpress install under 1 domain
- → Bigcommerce Repeating url
- → 301 Redirection from no-www to www in wordpress
- → Wrapper inside or outside HTML5 semantics main, which is best practice?