zencart安装SEO URL插件后出现重复网址或页面解决办法

本文介绍了一种在ZenCart中优化搜索引擎友好URL的方法,通过修改源代码实现对商品及分类页面URL的自动重定向,避免因URL不一致造成的搜索引擎收录问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个问题困扰了包括我在内的很多同志,今天看到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

如有侵权,请联系我,我将第一时间删除。

欢迎广大同行朋友拍砖。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值