mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 18:20:22 +00:00
adicionado tag canonical para url original e evitar duplicação se indexar
This commit is contained in:
parent
d3a534a7a5
commit
c28b844a96
1 changed files with 19 additions and 0 deletions
|
@ -660,6 +660,25 @@ class URLAnalyzer
|
|||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// Processa tags canônicas
|
||||
$canonicalLinks = $xpath->query("//link[@rel='canonical']");
|
||||
if ($canonicalLinks !== false) {
|
||||
// Remove todas as tags canônicas existentes
|
||||
foreach ($canonicalLinks as $link) {
|
||||
if ($link->parentNode) {
|
||||
$link->parentNode->removeChild($link);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Adiciona nova tag canônica com a URL original
|
||||
$head = $xpath->query('//head')->item(0);
|
||||
if ($head) {
|
||||
$newCanonical = $dom->createElement('link');
|
||||
$newCanonical->setAttribute('rel', 'canonical');
|
||||
$newCanonical->setAttribute('href', $url);
|
||||
$head->appendChild($newCanonical);
|
||||
}
|
||||
|
||||
// Sempre aplica a correção de URLs relativas
|
||||
$this->fixRelativeUrls($dom, $xpath, $url);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue