最近公司新上的网站被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]
注:这次后台就可以直接访问了 当然有两级目录的话就不行。

zencart分类页产品页去掉url中的id号的更多相关文章

  1. Dedecms去掉URL中a目录的方法

    本文实例讲述了Dedecms去掉URL中a目录的方法.分享给大家,供大家参考.具体分析如下: 使用dedecms的朋友可能会发现自己的URL目录生成是会自动带有一个/A/目录了,那么要如何去掉URL中 ...

  2. 【代码笔记】iOS-请求去掉url中的空格

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ...

  3. CI在nginx环境下去掉url中的index.php

    在nginx环境下CI框架默认URL规则访问不了,出现500错误,如: http://blog.php230.com/index.php/keywords 今天在服务器配置CI框架环境时,去除URL中 ...

  4. url中出现井号("#")的问题

    今天在asp.net mvc网站项目的前台页面里写一段js代码时,想要跳转到某个url,例如 location.href="xxxx?"+"id="+id+&q ...

  5. ASP.NET MVC Url中带点号出现404错误的解决方案

    由于项目需求,项目的路由设计如下 config.Routes.MapHttpRoute( name: "Get/Put Sku", routeTemplate: "api ...

  6. angluar去掉url中#

    众所周知,angular项目中路由机制会在地址栏加一个#来实现各个页面的切换,虽然url中有个#号也无伤大雅,但每次看到多一个这个东西总是不舒服(我不是强迫证啊),趁着项目间隙还是决定把它去掉. 去谷 ...

  7. VUE项目问题之:去掉url中的#/

    一.问题 使用VUE路由,项目的url总是带有锚点,如下: http://localhost:8082/#/ 二.解决 修改路由文件中 index.js 文件,即 src --> router ...

  8. CI去掉 URL 中的 index.php

    首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite 查找httpd.conf中是否开启了mod_rewrite.so 然后,在 CI 根目录下新建立一个配置文件,命名为 ...

  9. CI 框架去掉url 中index.php的方法

    1 修改 apache 的 httpd.conf 文件 #LoadModule rewrite_module modules/mod_rewrite.so 去掉前面的# 2 找到 你程序目录下的 .h ...

随机推荐

  1. 【BZOJ 1043】【HNOI 2008】下落的圆盘 判断圆相交+线段覆盖

    计算几何真的好暴力啊. #include<cmath> #include<cstdio> #include<cstring> #include<algorit ...

  2. poj3177 && poj3352 边双连通分量缩点

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12676   Accepted: 5368 ...

  3. Canvas是什么

    Canvas 是通过 JavaScript 来绘制 2D 图形,是 HTML 5 中新增的元素. Canvas 有如下特点: 绘制的是位图,图像放大后会失真. 不支持事件处理器. 能够以 .png 或 ...

  4. 数据库开发基础-SQl Server 存储过程

    存储过程: 存储过程(stored procedure)有时也称为sproc.存储过程存储于数据库中而不是在单独的文件中,有输入参数.输出参数以及返回值等. 在数据库中,创建存储过程和创建其他对象的过 ...

  5. iOS之类的本质

    1.本质 类的本质其实也是一个对象(类对象) 程序中第一次使用该类的时候被创建,在整个程序中只有一份. 此后每次使用都是这个类对象,它在程序运行时一直存在. 类对象是一种数据结构,存储类的基本信息:类 ...

  6. css-a与a:link的一些认识

    1.a元素有四种状态: a:link {color:blue;}//未点击的链接状态 a:visited {color:blue;}//已点击的连接状态 a:hover {color:red;}//鼠 ...

  7. 【BZOJ-2453&2120】维护队列&数颜色 分块 + 带修莫队算法

    2453: 维护队列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 653  Solved: 283[Submit][Status][Discuss] ...

  8. 【BZOJ-1692&1640】队列变换 后缀数组 + 贪心

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1153  Solved: 482[Submit][St ...

  9. codeforces 21D:Traveling Graph

    Description You are given undirected weighted graph. Find the length of the shortest cycle which sta ...

  10. Python简介及环境部署

    Python的由来:         Python的创始人:Guido van Rossum Guido 在1989年12月时,寻找一门“课余”编程项目来打发圣诞节前后的时间.Guido决定为当时正构 ...