URL经常变动的问题的解决

本文介绍了一种在Magento中稳定重写URL的方法,通过修改核心资源连接和从产品实体表中获取URL_key来生成SEO友好的URL。这种方法有助于提高网站的搜索引擎排名。

在magento中,URL,使用magento的方法的magento经常变动,做seo需要稳定的重写后URL譬如:

http://192.168.1.145:81/silverjewellerystores.com/jp/catalog/product/view/id/115/category/882/

我们希望是重写后的URL

http://192.168.1.145:81/silverjewellerystores.com/lovely-heart-style-925-silver-woman-bracelet-b001-283

可以通过下面的方法:

$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');

$productTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_varchar';

$store_idd = Mage::app()->getStore()->getId();

foreach($ids as $id){
$product_s = Mage::getModel('catalog/product')->load($id);
$select = $read->select()
->from(array('cp'=>$productTable))
->where('cp.entity_id=?', $id)
->where('cp.attribute_id=?',86)
->where('store_id=?',$store_idd)
->limit(3) ;
// echo $select;
$rows = $read->fetchAll($select);
foreach($rows as $row){
$product_url = Mage::getBaseUrl('web').$row['value'];
}
// $product_url = Mage::getBaseUrl('web').$rows[0]['value'];
$product_s->setProductUrls($product_url);
$_producttt[]= $product_s;
}

$tt = count($_producttt);
if($tt<10){
$ss = $tt;
}else{
$ss = 10;
}

$rand=array_rand($_producttt,$ss);
foreach ($rand as $v) {
$_products[]=$_producttt[$v];
}

原理大致为从catalog_product_entity_varchar表中取出URL_key,不同的magento安装后,好像URL_KEY对应的attribute_id貌似不一样,在我的系统里面是86,进而把ID对应的urlkey遍历出来,通过字符串拼接$product_url = Mage::getBaseUrl('web').$row['value'];得到重写后的URL,当然也和重写规则设置对应!!!!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值