zencart分类页产品页去掉url中的id号

最近公司新上的网站被seo指出要修改url,去掉url中产品id。由于我们用的是zencart框架,装了 Ultimate SEO URLs 插件,所以在网上应该有这方面的资料,本文主要参考资料:

       原网址:http://leezhxing.blog.51cto.com/6634351/1282790

 

   原文只介绍了修改产品页,我在修改过程中一并把分类页也进行了修改,下面为原文修改产品页内容,其中有些错误用红色字体更正。

 

以前用Ultimate SEO URLs模块 产品地址是这样的

http://www.xxx.com/产品名-p-101.html
通过下面方法我们改成这样的格式
http://www.xxx.com/产品名/

1.includes/init_includes/init_category_path.php(原先是includes/modules/pages/product_info/header_php.php 但不能引用到导航)
头部添加
if(zen_not_null($_GET['products_name'])){
$products_id_query=$db->Execute("select products_id from ".TABLE_PRODUCTS_DESCRIPTION.' where products_name="'.str_replace("-"," ",$_GET['products_name']).'"');
if($products_id_query->RecordCount()>0)
$_GET['products_id']=$products_id_query->fields['products_id'];
}
2.includes/classes/seo.url.php
约401行查找
$url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
替换为 
$url = $this->make_url($page, $this->get_product_name($p2[1]),'', '', '/', '');

此处替换为:$url = $this->make_url($page, $this->get_product_name($p2[1]), '', '', '.html', $separator);
3.htaccess
查找
RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
替换为
RewriteRule ^(.*)\/$ index\.php?main_page=product_info&products_name=$1&%{QUERY_STRING} [L]


注意事项 
1.产品名中不能出现- 可用空格来表示
2.产品名不能重复
3.类似后台admin这种的 必须要直接访问文件了 比如http://www.xxx.com/admin/index.php

-----------------------------更新分割线-----------------------------------------
有人问怎么样才能显示成http://www.xxx.com/目录名/产品名/ 这样的方式
修改方法如下
1.includes/init_includes/init_category_path.php(原先是includes/modules/pages/product_info/header_php.php 但不能引用到导航)
头部添加
if(zen_not_null($_GET['products_name'])){
$products_id_query=$db->Execute("select products_id from ".TABLE_PRODUCTS_DESCRIPTION.' where products_name="'.str_replace("-"," ",$_GET['products_name']).'"');
if($products_id_query->RecordCount()>0)
$_GET['products_id']=$products_id_query->fields['products_id'];
}
2.includes/classes/seo.url.php
约401行查找
$url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
替换为 
$url = $this->make_url($page, zen_get_categories_name_from_product($p2[1]).'/'.$this->get_product_name($p2[1]),'', '', '/', '');

3..htaccess
查找
RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
替换为
RewriteRule ^(.*)\/(.*)\/$ index\.php?main_page=product_info&products_name=$2&%{QUERY_STRING} [L]
注:这次后台就可以直接访问了 当然有两级目录的话就不行。

 

posted @ 2013-09-02 14:12  leezhxing  阅读(913)  评论(0编辑  收藏  举报