最近公司新上的网站被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. JAVA1种C++3种继承方式

    JAVA中只有一种public继承

  2. thinkphp全站静态页实现方法

    1:在根目录下的全局index.php中加下面这行: define('HTML_PATH', './htm');//生成静态页面的文件位置 2:在项目的配置文件config.php中加下面这行: 'H ...

  3. 跨域http请求

    <?php header("Access-Control-Allow-Origin: *"); header("Content-Type: application/ ...

  4. 【USACO 1.5】SuperPrime Rib

    /* TASK: sprime LANG: C++ SOLVE: dfs,后面每增加一位,判断当前是否为素数. 第一位不能为0 */ #include<cstdio> int n; voi ...

  5. 【BZOJ-3696】化合物 树形DP + 母函数(什么鬼)

    3696: 化合物 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 165  Solved: 85[Submit][Status][Discuss] D ...

  6. Linux VFS Extended Attribute And Access Control Table

    catalog . 简介 . 扩展属性 . 访问控制表 . 小结 0. 简介 许多文件系统都提供了一些特性,扩展了VFS层提供的标准功能,虚拟文件系统不可能为所有特性都提供具体的数据结构.超出标准的U ...

  7. RabbitMQ 通过记日志来看routingkey

    RoutingKey 每个项目都需要记录日志,日志则一般会分为多种级别,常见的是 Info.debug.warn.Error 对于前三种日志,在项目运行中会产生大量的消息,但是一般多数情况下是不会用到 ...

  8. CentOS禁用触摸板

    安装xorg-x11-apps包 yum install xorg-x11-apps 查看设备信息 cd /dev/input/ ls //找到触摸板信息 xinput list //找到触摸板的id ...

  9. C++ 之 const references

    extraction from The C++ Programming Language 4th. ed., Section 7.7 References, Bjarne Stroustrup To ...

  10. codevs 3143 二叉树的序遍历

    传送门 Description 求一棵二叉树的前序遍历,中序遍历和后序遍历 Input 第一行一个整数n,表示这棵树的节点个数. 接下来n行每行2个整数L和R.第i行的两个整数Li和Ri代表编号为i的 ...