2013-11-01 189 views
0

我目前的opencart商店url結構是http://www.mydomain.com/categoryName/productName,但是當有人點擊它時,它將被重定向到www.mydomain.com/productName,這將導致301頁上的很多內容,所以我想要將產品頁面URL更改爲www.mydomain.com/productName(刪除類別名稱)。但我無法在cms後端找到任何選項,所以我想我必須破解主題模板文件才能做到這一點?有誰知道如何做到這一點?如何更改opencart url結構

我很新的opencart所以任何幫助將不勝感激。

感謝

+0

我會去了解一下爲什麼用戶從'/分類/ product'只是'/ product'重定向的原因並嘗試解決(刪除)該重定向...這可能會更容易和更合理... – shadyyx

回答

0

如果這僅僅是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。

-1

只需在OpenCart中啓用SEO網址即可。 默認情況下SEO網址已關閉。我們必須首先啓用它們。

  1. 進入管理面板 - >系統 - >設置。

  2. 點擊商店名稱右側的「編輯」鏈接。 存儲設置

  3. 單擊「服務器」選項卡。你會發現一個選項 - 「使用SEO網址」。點擊它前面的「是」。保存選項。
0

1) First you should have to Go to Admin Panel > Setting > Click Edit Your Template and Click Server Tab then Enable Use SEO URLs <br> 
 
2) Go to root folder .htaccess.txt open in editer and save as only .htaccess without extension save remember! your rewrite module setting should be on if you have using xampp or wamp.<br> 
 
3) Now Go to catalog/controller/common/seo_url.php open this file and find this Code <br> 
 
$url .= '/' . $query->row['keyword'];<br> 
 
Replace to this<br> 
 
$url .= '/product/' . $query->row['keyword'];<br> 
 
4) Save Now go to your main page and click any product you will see like this<br> 
 
www.example.com/product/macbook.<br><br> 
 
Regard!<br> 
 
Shehroz