zencart安裝SEO URL插件後出現重複網址或頁面解決辦法

這個問題困擾了包括我在內的很多同志,今天看到zen-cart.cn上面Jack老大回復的一個帖子,把它轉過來大家一起參考下。

 

首先,商店設置-搜索引擎優化-打開自動跳轉嗎?,設置爲 true
然後打開文件 \includes\classes\seo.url.php

$this->attributes['SEO_REDIRECT']['NEED_REDIRECT'] = $this->need_redirect ? 'true' : 'false';


在其前面加上以下代碼:

    // check product name from URL and redirect if not equal to real product name to avoid duplicates
      if ( preg_match('/-p-[0-9]/i', $this->uri) && preg_match('/main_page=product_info/i', $this->real_uri) ) {
         $productname_from_url = preg_replace('/-p-[0-9].*/i','',$this->uri);
         $productid_from_url= preg_replace('/.*-p-([0-9]+)\.html/i','$1',$this->uri);
         if ( $this->get_product_name($productid_from_url) != $productname_from_url ) {
            $this->need_redirect = true;
         // repeating procedure from function check_redirect() but for real_uri
         if ($this->is_attribute_string($this->real_uri)) {
         $parsed_url = parse_url($this->real_uri);
         $this->uri_parsed = parse_url($parsed_url['scheme']);
         $this->uri_parsed['query'] = preg_replace('/products_id=([0-9]+)/', 'products_id=$1:' . $parsed_url['path'], $this->uri_parsed['query']);
      } else {
         $this->uri_parsed = parse_url($this->real_uri);
      }
         }
      } // end of product_info URL redirect

    // check category name from URL and redirect if not equal to real category name to avoid duplicates
      if ( preg_match('/-c-[0-9]/i', $this->uri) && preg_match('/main_page=index/i', $this->real_uri) ) {
         $categoryname_from_url = preg_replace('/-c-[0-9].*/i','',$this->uri);
         $categoryid_from_url= preg_replace('/.*-c-([0-9]+)\.html/i','$1',$this->uri);
         if ( $this->get_category_name($categoryid_from_url) != $categoryname_from_url ) {
            $this->need_redirect = true;
         // repeating procedure from function check_redirect() but for real_uri
         if ($this->is_attribute_string($this->real_uri)) {
         $parsed_url = parse_url($this->real_uri);
         $this->uri_parsed = parse_url($parsed_url['scheme']);
         $this->uri_parsed['query'] = preg_replace('/cPath=([0-9]+)/', 'cPath=$1:' . $parsed_url['path'], $this->uri_parsed['query']);
      } else {
         $this->uri_parsed = parse_url($this->real_uri);
      }
         }
      } // end of category URL redirect


上面的代碼,自動分析請求的URL,如果URL中分類、商品名稱與數據庫裏的不一樣,就自動跳轉到正確的頁面,這樣就消除了重複URL。對分類頁面和商品頁面都有效。

that 's all .

 

免責生明:

本內容轉載自:http://www.zen-cart.cn/forum/topic14264.html

如有侵權,請聯繫我,我將第一時間刪除。

歡迎廣大同行朋友拍磚。

 

 

發佈了34 篇原創文章 · 獲贊 42 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章