Opencart实现产品URL静态化,地址不含分类和厂商路径
opencart启用URL静态化后,产品的URL地址会有多个,在
- 类目一下是这个链接:http://127.0.0.1/components/cinema.html
- 类目二下是这个链接:http://127.0.0.1/components/monitors/cinema.html
- 厂商下又是这个链接:http://127.0.0.1/apple/cinema.html
明明就是一个产品,却有多个链接,这对于SEO来说,这么多个地址会平分了权重,对搜索引擎优化排名很不利,所以我们需要修改一下,需要修改两个文件。
1、/catalog/controller/product/category.php
通过关键词$result['product_id']找到如下代码:
$data['products'][]=array( 'product_id'=>$result['product_id'], 'thumb'=>$image, 'name'=>$result['name'], 'description'=>utf8_substr(strip_tags(html_entity_decode($result['description'],ENT_QUOTES,'UTF-8')),0,$this->config->get('config_product_description_length')).'..', 'price'=>$price, 'special'=>$special, 'tax'=>$tax, 'rating'=>$result['rating'], 'href'=>$this->url->link('product/product','path='.$this->request->get['path'].'&product_id='.$result['product_id'].$url) );
把最后一行代码的的. $this->request->get['path']去掉,包括前面的一个“.”连接符,变成这样:
'href'=>$this->url->link('product/product','path='.'&product_id='.$result['product_id'].$url)
2、/catalog/model/tool/seo_url.php
通过关键词$query->row['keyword'] 搜索到如下的内容:
if(($data['route']=='product/product'&&$key=='product_id')||(($data['route']=='product/manufacturer/info'||$data['route']=='product/product')&&$key=='manufacturer_id')||($data['route']=='information/information'&&$key=='information_id')){ $query=$this->db->query("SELECT*FROM".DB_PREFIX."url_aliasWHERE`query`='".$this->db->escape($key.'='.(int)$value)."'"); if($query->num_rows&&$query->row['keyword']){ $url.='/'.$query->row['keyword']; unset($data[$key]); } }elseif($key=='path'){
将中间的if语句改成:
if($query->num_rows&&$query->row['keyword']){ if($key=='product_id'){ $url='/'.$query->row['keyword']; }else{ $url.='/'.$query->row['keyword']; } unset($data[$key]); }
这样,所有位置的链接就只有一个了:http://127.0.0.1/apple/cinema.html
参考资料:http://kingplesk.org/2011/05/opencart-seo-url-%E4%BC%98%E5%8C%96%E8%BF%9B%E9%98%B6/。