# 修改seo url中去掉产品id的方法

**URL:** <https://www.isharkfly.com/t/seo-url-id/3162>\
**Category:** PHP\
**Created:** [August 14, 2012, 3:02am UTC](https://www.isharkfly.com/t/seo-url-id/3162 "2012-08-14T03:02:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 14, 2012, 3:02am UTC](https://www.isharkfly.com/t/seo-url-id/3162/1 "2012-08-14T03:02:08Z")

</div>

以前用Ultimate SEO URLs模块 产品地址是这样的  
[http://www.xxx.com/](http://www.xxx.com/)产品名-p-101.html  
通过下面方法我们改成这样的格式  
[http://www.xxx.com/](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]`注:这次后台就可以直接访问了 当然有两级目录的话就不行
