关于url重写,伪静态问题
2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家
如:ecshop.com/goods_123.html。 问题:怎么可以将goods改为每个商品的名称? |
回答:
帮顶同求不过除非商品是英文 不然就太乱了 |
我也遇到这个问题了....高手出来帮忙解答一下 |
英文外贸网站,不会出现中文的。昨天等不到我自己找了一个: 在include/lib_commom.php里面,把下面这段function build_uri($app, $params, $append = '', $page = 0, $keywords = '', $size = 0) { static $rewrite = NULL; if ($rewrite === NULL) { $rewrite = intval($GLOBALS['_CFG']['rewrite']); } $args = array('cid'=> 0, 'gid'=> 0, 'bid'=> 0, 'acid'=> 0, 'aid'=> 0, 'sid'=> 0, 'gbid'=> 0, 'auid'=> 0, 'sort'=> '', 'order' => '', ); extract(array_merge($args, $params)); $uri = ''; switch ($app) { case 'category': if (empty($cid)) { return false; } else { if ($rewrite) { $uri = 'category-' . $cid; if (isset($bid)) { $uri .= '-b' . $bid; } if (isset($price_min)) { $uri .= '-min'.$price_min; } if (isset($price_max)) { $uri .= '-max'.$price_max; } if (isset($filter_attr)) { $uri .= '-attr' . $filter_attr; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'category.php?id=' . $cid; if (!empty($bid)) { $uri .= '&brand=' . $bid; } if (isset($price_min)) { $uri .= '&price_min=' . $price_min; } if (isset($price_max)) { $uri .= '&price_max=' . $price_max; } if (!empty($filter_attr)) { $uri .='&filter_attr=' . $filter_attr; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } } break; |
case 'goods': if (empty($gid)) { return false; } else { $uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid; } break; case 'brand': if (empty($bid)) { return false; } else { if ($rewrite) { $uri = 'brand-' . $bid; if (isset($cid)) { $uri .= '-c' . $cid; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'brand.php?id=' . $bid; if (!empty($cid)) { $uri .= '&cat=' . $cid; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } } break; case 'article_cat': if (empty($acid)) { return false; } else { if ($rewrite) { $uri = 'article_cat-' . $acid; if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } if (!empty($keywords)) { $uri .= '-' . $keywords; } } else { $uri = 'article_cat.php?id=' . $acid; if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } if (!empty($keywords)) { $uri .= '&keywords=' . $keywords; } } } break; case 'article': if (empty($aid)) { return false; } else { $uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid; } break; case 'group_buy': if (empty($gbid)) { return false; } else { $uri = $rewrite ? 'group_buy-' . $gbid : 'group_buy.php?act=view&id=' . $gbid; } break; case 'auction': if (empty($auid)) { return false; } else { $uri = $rewrite ? 'auction-' . $auid : 'auction.php?act=view&id=' . $auid; } break; case 'snatch': if (empty($sid)) { return false; } else { $uri = $rewrite ? 'snatch-' . $sid : 'snatch.php?id=' . $sid; } break; case 'search': break; case 'exchange': if ($rewrite) { $uri = 'exchange-' . $cid; if (isset($price_min)) { $uri .= '-min'.$price_min; } if (isset($price_max)) { $uri .= '-max'.$price_max; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'exchange.php?cat_id=' . $cid; if (isset($price_min)) { $uri .= '&integral_min=' . $price_min; } if (isset($price_max)) { $uri .= '&integral_max=' . $price_max; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } break; case 'exchange_goods': if (empty($gid)) { return false; } else { $uri = $rewrite ? 'exchange-id' . $gid : 'exchange.php?id=' . $gid . '&act=view'; } break; default: return false; break; } if ($rewrite) { if ($rewrite == 2 && !empty($append)) { $uri .= '-' . urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append)); } $uri .= '.html'; } if (($rewrite == 2) && (strpos(strtolower(EC_CHARSET), 'utf') !== 0)) { $uri = urlencode($uri); } return $uri; } |
更改为以下的: function build_uri($app, $params, $append = '', $page = 0, $size = 0) { static $rewrite = NULL; if ($rewrite === NULL) { $rewrite = intval($GLOBALS['_CFG']['rewrite']); } $args = array('cid' => 0, 'gid' => 0, 'bid' => 0, 'acid' => 0, 'aid' => 0, 'sid' => 0, 'gbid' => 0, 'auid' => 0, 'sort' => '', 'order' => '', ); extract(array_merge($args, $params)); $uri = ''; switch ($app) { case 'category': if (empty($cid)) { return false; } else { if ($rewrite) { $name = urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append)); $uri = 'simulation-'.$name.'-' . $cid; if (isset($bid)) { $uri .= '-b' . $bid; } if (isset($price_min)) { $uri .= '-min'.$price_min; } if (isset($price_max)) { $uri .= '-max'.$price_max; } if (isset($filter_attr)) { $uri .= '-attr' . $filter_attr; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'category.php?id=' . $cid; if (!empty($bid)) { $uri .= '&brand=' . $bid; } if (isset($price_min)) { $uri .= '&price_min=' . $price_min; } if (isset($price_max)) { $uri .= '&price_max=' . $price_max; } if (!empty($filter_attr)) { $uri .='&filter_attr=' . $filter_attr; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } } break; |
case 'goods': if (empty($gid)) { return false; } else { //$uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid; $name = urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append)); $uri = 'simulation-'.$name.'-g' . $gid; } break; case 'brand': if (empty($bid)) { return false; } else { if ($rewrite) { $uri = 'brand-' . $bid; if (isset($cid)) { $uri .= '-c' . $cid; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'brand.php?id=' . $bid; if (!empty($cid)) { $uri .= '&cat=' . $cid; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } } break; case 'article_cat': if (empty($acid)) { return false; } else { if ($rewrite) { $uri = 'article_cat-' . $acid; if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'article_cat.php?id=' . $acid; if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } } break; case 'article': if (empty($aid)) { return false; } else { $uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid; } break; case 'group_buy': if (empty($gbid)) { return false; } else { $uri = $rewrite ? 'group_buy-' . $gbid : 'group_buy.php?act=view&id=' . $gbid; } break; case 'auction': if (empty($auid)) { return false; } else { $uri = $rewrite ? 'auction-' . $auid : 'auction.php?act=view&id=' . $auid; } break; case 'snatch': if (empty($sid)) { return false; } else { $uri = $rewrite ? 'snatch-' . $sid : 'snatch.php?id=' . $sid; } break; case 'search': break; case 'exchange': if ($rewrite) { $uri = 'exchange-' . $cid; if (isset($price_min)) { $uri .= '-min'.$price_min; } if (isset($price_max)) { $uri .= '-max'.$price_max; } if (!empty($page)) { $uri .= '-' . $page; } if (!empty($sort)) { $uri .= '-' . $sort; } if (!empty($order)) { $uri .= '-' . $order; } } else { $uri = 'exchange.php?cat_id=' . $cid; if (isset($price_min)) { $uri .= '&integral_min=' . $price_min; } if (isset($price_max)) { $uri .= '&integral_max=' . $price_max; } if (!empty($page)) { $uri .= '&page=' . $page; } if (!empty($sort)) { $uri .= '&sort=' . $sort; } if (!empty($order)) { $uri .= '&order=' . $order; } } break; case 'exchange_goods': if (empty($gid)) { return false; } else { $uri = $rewrite ? 'exchange-id' . $gid : 'exchange.php?id=' . $gid . '&act=view'; } break; default: return false; break; } if ($rewrite) { if ($rewrite == 2 && !empty($append)&&$app!='category')//我多加了一个条件 { $uri .= '-' . urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append)); } $uri .= '.html'; } if (($rewrite == 2) && (strpos(strtolower(EC_CHARSET), 'utf') !== 0)) { $uri = urlencode($uri); } return $uri; } |
然后.htaccess也要修改: RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)\.html$category\.php\?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6&page=$7&sort=$8&order=$9 [QSA,L] RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)\.html$category\.php\?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6 [QSA,L] RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html$category\.php\?id=$2&brand=$3&page=$4&sort=$5&order=$6 [QSA,L] RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-([0-9]+)\.html$category\.php\?id=$2&brand=$3&page=$4 [QSA,L] RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)\.html$category\.php\?id=$2&brand=$3 [QSA,L] RewriteRule ^simulation-(.*)-([0-9]+)\.html$category\.php\?id=$2 [QSA,L] RewriteRule ^simulation-(.*)-g([0-9]+)\.html$goods\.php\?id=$2 [QSA,L] 改成你们想要的就可以了 |
很好啊 这个 是个思路 |
好教程,EC人才真多....谢谢分享,收藏了 |
自带的规则就有 ecshop学习资料:http://www.phpally.com |
帮顶帮顶 |
我也遇到这个问题了....高手出来帮忙解答一下 |
最近更新
常用插件
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
- ecshop商品分类名称增加样
ecshop插件介绍:本插件可以方便在后台管理,为ecshop商品分类名称增加样...
- ecshop分类批量扩展插件
ecshop分类批量扩展插件,这个插件是ecshop插件里面比较核心的插件。我们...
- ecshop二次商品订购人信息
ecshop二次商品订购人信息填写插件,有时候给朋友送花,或者是送礼品的...
- ecshop2.7.1打印发货单插件
ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs...
ecshop热门问答
ecshop热门资料
ecshop集成飞信
ecshop登陆后台出错
ecshop祖国
ecshop国产软件
ecshop地域
ecshop日历
ecshop免费客服代码
ecshop本地
ecshopnookshop
ecshop太阳能热水器
ecshop银行
nginx
ecshop赠品
ecshop谷歌搜索
ecshopECShop教程
ecshop清理
ecshop手机中国
ecshopFTP
ecshop调用留言
ecshoponce
ecshop访问者
ecshop缺省
ecshop忽悠
ecshop商品分类
ecshop团队合作
ecshop烦请
ecshop模板设计
微信浏览器
ecshop解释
ecshop限时