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

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

欢迎广大同行朋友拍砖。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ZenCart URL目录式链接Ceon Url Mapping SEO插件,这款插件也是大家比较喜欢的,唯一的缺点就是不自动生成友好的url,需要你手动填写url,去后台分类,产品处单击更新下才能生成,现在官方有支持zencart 1.5的,强创网络这里提供下载地址给大家下载,顺便介绍大概安装方法。 首先安装zencart系统后,看你安装zencart是否已经集成SEO插件,如果有就先卸载掉,直接下来就是安装ZenCart SEO插件ceon url mapping,它可以实现url的目录式静态化。 1、首先去官方下载zencart模块Ceon URI Mapping (SEO)-1.5.0 2、解开压缩包后,里面有_docs(说明文档)、files、modified_core_files、template_override_files、third_party_module_integration这四个都是需要上传安装的文件,注意这里面后台admin改成你的后台目录名,includes里面还会有模板名也修改成你的。 3、把文件都上传好后,打开zencart后台。 4、找到 Modules > Ceon URI Mapping (SEO) Config,可以进行一些设置,一般默认就可以了。 5、一般主要有4类:Category、Product、Manufacturer、EZ-Page。比如分类url的优化:后台找到Catalog > Categories/Products,然后编辑或新加一个产品,最下面有url选项。麻烦吧,对于批量建站的,产品又多的人肯定会觉得特别麻烦,此模块有自动处理的模块名叫:URI Mappings Manager,不过是是收费的。 6、添加url重写规则.htaccess 1)如果网站安装在域名根目录,那么在网店安装文件夹下,新建立一个.htaccess文件,加上以下代码: RewriteEngine On # Don't rewrite any URIs ending with a file extension (ending with .[xxxxx]) RewriteCond %{REQUEST_URI} !\.[a-z]{2,5}$ [NC] # Don't rewrite admin directory RewriteCond %{REQUEST_URI} !^/admin [NC] # Don't rewrite editors directory RewriteCond %{REQUEST_URI} !^/editors [NC] # Don't rewrite cPanel directories RewriteCond %{REQUEST_URI} !/cpanel [NC] RewriteCond %{REQUEST_URI} !/frontend [NC] # Handle all other URIs using Zen Cart (index.php) RewriteRule .* index.php?%{QUERY_STRING} [L] 2)如果网站安装在文件夹下,那么规则如下: RewriteEngine On # ONLY rewrite URIs beginning with /qcweb/ RewriteCond %{REQUEST_URI} ^/qcweb/ [NC] # Don't rewrite any URIs ending with a file extension (ending with .[xxxxx]) RewriteCond %{REQUEST_URI} !\.[a-z]{2,5}$ [NC] # Don't rewrite admin directory RewriteCond %{REQUEST_URI} !^/qcweb/admin [NC] # Don't rewrite editors directory RewriteCond %{REQUEST_URI} !^/qcweb/editors [NC] # Don't rewrite cPanel directories RewriteCond %{REQUEST_URI} !/cpanel [NC] RewriteCond %{REQUEST_URI} !/frontend [NC] # Handle all other URIs using Zen Cart (index.php) RewriteRule .* index.php?%{QUERY_STRING} [L] 到此为止zencart插件安装完毕,快去后台编辑下分类和产品的URL,生成后就可以访问了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值