Jooma 3.9 — how to put rel="canonical" only on the version of the site http?

When moving from http to https Yandex asks the following:

Canonical url
In the source code of each page of the old site, add a link to a similar page with the new attribute rel="canonical".

For example, you change address example.com on https://example.com. On the page example.com/main you need to specify:

< link rel="canonical" href="https://example.com/main"/ >



How it can be implemented in Joomla? Help make the condition in head.php
March 19th 20 at 08:41
1 answer
March 19th 20 at 08:43
Install the extension.
cost script

<?php 
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { 
//$protocol = 'https://'; 
} else { 
//$protocol = 'http://'; 
$doc -> addCustomTag(' 
<link rel="canonical" href="https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'" /> 
'); 
} 
?>
- ford90 commented on March 19th 20 at 08:46
The right thing to do appropriate redirect pages from http to https. In Joomla 3 it is very simple:
System→ General settings → Server → Enable SSL.

If there are difficulties with the translation of Joomla website on https Protocol see here. - ottis commented on March 19th 20 at 08:49
@ford90, but where put the script? head.php?
After a year of work? The weight of links has been transferred in full? - Donavon_Colli commented on March 19th 20 at 08:52
@Donavon_Colli, Yes, all is well. - ford90 commented on March 19th 20 at 08:55
@ottis, System→ General settings → Server → Enable SSL. is PHP redirect , it is better to add to this using .htaccess - ford90 commented on March 19th 20 at 08:58

Find more questions by tags Joomla