如果這僅僅是SEO的原因,可考慮只使用一個rel=canonical
link元素在你的head
。
在/system/library/document.php
添加以下內容:
private $canonical = null;
public function setCanonical($canonical) {
$this->canonical= $canonical;
}
public function getCanonical() {
return $this->canonical;
}
在/catalog/controller/product/product.php
:
查找行:$this->document->setTitle($product_info['name']);
並添加之前:$this->document->setCanonical($this->url->link('product/product', 'product_id=' . $product_id));
最後,在你的主題common/header.tpl
文件,請在內的任何位置添加以下內容元件:
<?php if ($this->document->getCanonical()): ?>
<link rel="canonical" href="<?php echo $this->document->getCanonical(); ?>"/>
<?php endif; ?>
應該是這樣。
您可以使用上述原則以與上述產品控制器相同的方式修改您的類別,製造商和信息頁面控制器,以確保您不會在這些頁面上獲得重複的內容SEO問題。
如果您確實想要添加301重定向,則需要檢查當前頁面URL是否與上述getCanonical()
方法返回的頁面匹配 - 如果不匹配,則重定向到規範URL。
我會去了解一下爲什麼用戶從'/分類/ product'只是'/ product'重定向的原因並嘗試解決(刪除)該重定向...這可能會更容易和更合理... – shadyyx