刚修改的伪静态分类URL

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

我刚写的的确还全部测试,先放上来,大家如果用的话 记得做好备份,呵呵。

1、lib_common.php build_uri 我做了修改 我把整个函数贴出来

  1. function build_uri($app, $params, $append = '', $page = 0, $size = 0)
  2. {
  3. static $rewrite = NULL;

  4. if ($rewrite === NULL)
  5. {
  6. $rewrite = intval($GLOBALS['_CFG']['rewrite']);
  7. }

  8. $args = array('cid' => 0,
  9. 'gid' => 0,
  10. 'bid' => 0,
  11. 'acid' => 0,
  12. 'aid' => 0,
  13. 'sid' => 0,
  14. 'gbid' => 0,
  15. 'auid' => 0,
  16. 'sort' => '',
  17. 'order' => '',
  18. );

  19. extract(array_merge($args, $params));
  20. $uri = '';
  21. switch ($app)
  22. {
  23. case 'category':
  24. if (empty($cid))
  25. {
  26. return false;
  27. }
  28. else
  29. {
  30. if ($rewrite)
  31. {
  32. $name = urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
  33. $uri = 'wholesale-'.$name.'-' . $cid;
  34. if (isset($bid))
  35. {
  36. $uri .= '-b' . $bid;
  37. }
  38. if (isset($price_min))
  39. {
  40. $uri .= '-min'.$price_min;
  41. }
  42. if (isset($price_max))
  43. {
  44. $uri .= '-max'.$price_max;
  45. }
  46. if (isset($filter_attr))
  47. {
  48. $uri .= '-attr' . $filter_attr;
  49. }
  50. if (!empty($page))
  51. {
  52. $uri .= '-' . $page;
  53. }
  54. if (!empty($sort))
  55. {
  56. $uri .= '-' . $sort;
  57. }
  58. if (!empty($order))
  59. {
  60. $uri .= '-' . $order;
  61. }
  62. }
  63. else
  64. {
  65. $uri = 'category.php?id=' . $cid;
  66. if (!empty($bid))
  67. {
  68. $uri .= '&brand=' . $bid;
  69. }
  70. if (isset($price_min))
  71. {
  72. $uri .= '&price_min=' . $price_min;
  73. }
  74. if (isset($price_max))
  75. {
  76. $uri .= '&price_max=' . $price_max;
  77. }
  78. if (!empty($filter_attr))
  79. {
  80. $uri .='&filter_attr=' . $filter_attr;
  81. }

  82. if (!empty($page))
  83. {
  84. $uri .= '&page=' . $page;
  85. }
  86. if (!empty($sort))
  87. {
  88. $uri .= '&sort=' . $sort;
  89. }
  90. if (!empty($order))
  91. {
  92. $uri .= '&order=' . $order;
  93. }
  94. }
  95. }

  96. break;
  97. case 'goods':
  98. if (empty($gid))
  99. {
  100. return false;
  101. }
  102. else
  103. {
  104. $uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid;
  105. }

  106. break;
  107. case 'brand':
  108. if (empty($bid))
  109. {
  110. return false;
  111. }
  112. else
  113. {
  114. if ($rewrite)
  115. {
  116. $uri = 'brand-' . $bid;
  117. if (isset($cid))
  118. {
  119. $uri .= '-c' . $cid;
  120. }
  121. if (!empty($page))
  122. {
  123. $uri .= '-' . $page;
  124. }
  125. if (!empty($sort))
  126. {
  127. $uri .= '-' . $sort;
  128. }
  129. if (!empty($order))
  130. {
  131. $uri .= '-' . $order;
  132. }
  133. }
  134. else
  135. {
  136. $uri = 'brand.php?id=' . $bid;
  137. if (!empty($cid))
  138. {
  139. $uri .= '&cat=' . $cid;
  140. }
  141. if (!empty($page))
  142. {
  143. $uri .= '&page=' . $page;
  144. }
  145. if (!empty($sort))
  146. {
  147. $uri .= '&sort=' . $sort;
  148. }
  149. if (!empty($order))
  150. {
  151. $uri .= '&order=' . $order;
  152. }
  153. }
  154. }

  155. break;
  156. case 'article_cat':
  157. if (empty($acid))
  158. {
  159. return false;
  160. }
  161. else
  162. {
  163. if ($rewrite)
  164. {
  165. $uri = 'article_cat-' . $acid;
  166. if (!empty($page))
  167. {
  168. $uri .= '-' . $page;
  169. }
  170. if (!empty($sort))
  171. {
  172. $uri .= '-' . $sort;
  173. }
  174. if (!empty($order))
  175. {
  176. $uri .= '-' . $order;
  177. }
  178. }
  179. else
  180. {
  181. $uri = 'article_cat.php?id=' . $acid;
  182. if (!empty($page))
  183. {
  184. $uri .= '&page=' . $page;
  185. }
  186. if (!empty($sort))
  187. {
  188. $uri .= '&sort=' . $sort;
  189. }
  190. if (!empty($order))
  191. {
  192. $uri .= '&order=' . $order;
  193. }
  194. }
  195. }

  196. break;
  197. case 'article':
  198. if (empty($aid))
  199. {
  200. return false;
  201. }
  202. else
  203. {
  204. $uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
  205. }

  206. break;
  207. case 'group_buy':
  208. if (empty($gbid))
  209. {
  210. return false;
  211. }
  212. else
  213. {
  214. $uri = $rewrite ? 'group_buy-' . $gbid : 'group_buy.php?act=view&id=' . $gbid;
  215. }

  216. break;
  217. case 'auction':
  218. if (empty($auid))
  219. {
  220. return false;
  221. }
  222. else
  223. {
  224. $uri = $rewrite ? 'auction-' . $auid : 'auction.php?act=view&id=' . $auid;
  225. }

  226. break;
  227. case 'snatch':
  228. if (empty($sid))
  229. {
  230. return false;
  231. }
  232. else
  233. {
  234. $uri = $rewrite ? 'snatch-' . $sid : 'snatch.php?id=' . $sid;
  235. }

  236. break;
  237. case 'search':
  238. break;
  239. case 'exchange':
  240. if ($rewrite)
  241. {
  242. $uri = 'exchange-' . $cid;
  243. if (isset($price_min))
  244. {
  245. $uri .= '-min'.$price_min;
  246. }
  247. if (isset($price_max))
  248. {
  249. $uri .= '-max'.$price_max;
  250. }
  251. if (!empty($page))
  252. {
  253. $uri .= '-' . $page;
  254. }
  255. if (!empty($sort))
  256. {
  257. $uri .= '-' . $sort;
  258. }
  259. if (!empty($order))
  260. {
  261. $uri .= '-' . $order;
  262. }
  263. }
  264. else
  265. {
  266. $uri = 'exchange.php?cat_id=' . $cid;
  267. if (isset($price_min))
  268. {
  269. $uri .= '&integral_min=' . $price_min;
  270. }
  271. if (isset($price_max))
  272. {
  273. $uri .= '&integral_max=' . $price_max;
  274. }

  275. if (!empty($page))
  276. {
  277. $uri .= '&page=' . $page;
  278. }
  279. if (!empty($sort))
  280. {
  281. $uri .= '&sort=' . $sort;
  282. }
  283. if (!empty($order))
  284. {
  285. $uri .= '&order=' . $order;
  286. }
  287. }

  288. break;
  289. case 'exchange_goods':
  290. if (empty($gid))
  291. {
  292. return false;
  293. }
  294. else
  295. {
  296. $uri = $rewrite ? 'exchange-id' . $gid : 'exchange.php?id=' . $gid . '&act=view';
  297. }

  298. break;
  299. default:
  300. return false;
  301. break;
  302. }

  303. if ($rewrite)
  304. {
  305. if ($rewrite == 2 && !empty($append)&&$app!='category')//我多加了一个条件
  306. {
  307. $uri .= '-' . urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
  308. }

  309. $uri .= '.html';
  310. }
  311. if (($rewrite == 2) && (strpos(strtolower(EC_CHARSET), 'utf') !== 0))
  312. {
  313. $uri = urlencode($uri);
  314. }
  315. return $uri;
  316. }
复制代码


2、.htaccess做了修改

  1. RewriteRule ^wholesale-(.*)-c([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]
  2. RewriteRule ^wholesale-(.*)-c([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]
  3. RewriteRule ^wholesale-(.*)-c([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]
  4. RewriteRule ^wholesale-(.*)-c([0-9]+)-b([0-9]+)-([0-9]+)\.html$ category\.php\?id=$2&brand=$3&page=$4 [QSA,L]
  5. RewriteRule ^wholesale-(.*)-c([0-9]+)-b([0-9]+)\.html$ category\.php\?id=$2&brand=$3 [QSA,L]
  6. RewriteRule ^wholesale-(.*)-c([0-9]+)\.html$ category\.php\?id=$2 [QSA,L]
复制代码

出现的结果类似:http://www.xaphp.com/wholesale-Computers++Networki-c48-b0.html我不知道对大家是否有用

回答:
导航栏分类确实需要伪静态。支持了

这个要支持一下!好东东!

加上这些就是伪静态了??还得配置自己的服务器吧!!

楼主链接出错了啊

楼主您好我按照您的方法修改了静态链接方式,

效果达到了,但是却提示 页面不存在!

不知道是什么问题能帮忙解答下吗?

这个要看部分服务器 是否支持哦!~

支持下,不错

又学会了一招,谢谢了

看看啊看看

好用的东东