準(zhǔn)備自己搭建虛擬版的城市分站
借助聯(lián)動(dòng)菜單
首先自編URL:
index.php?c=show&id=28921&city=123(可以正常訪問,且可以獲取數(shù)據(jù))
在模板里用下面的代碼獲取city的值(聯(lián)動(dòng)菜單的ID值)。
<?php $url=$_SERVER["QUERY_STRING"]; $city = substr($url,strripos($url,"city=")+5); ?>
再用獲取城市地名:
內(nèi)容:{dr_linkage('address',$city,0,'name')}
現(xiàn)在要解決地址靜態(tài)化的問題
我用下面的代碼:
"([A-za-z0-9 \-\_]+)\/u([0-9]+)\/([0-9]+)\.html" => "index.php?c=show&id=$2&city=$1",
訪問如:http://192.168.0.100/zixun/u121/200.html
其中u121中的121是城市ID
其中200.html中的200是文章ID
得到的是id為121的內(nèi)容了。該如何解決。
求大俠幫助,謝謝。
附rewrite.php全部代碼!
<?php
/**
* URL解析規(guī)則
* 例如: 114.html 對(duì)應(yīng) index.php?s=demo&c=show&id=114
* 可以解析: "114.html" => 'index.php?s=demo&c=show&id=114',
* 動(dòng)態(tài)id解析: "([0-9]+).html" => 'index.php?s=demo&c=show&id=$1',
*/
return [
"list-([A-za-z0-9 \-\_]+)-([0-9]+)\.html" => "index.php?c=category&dir=$1&page=$2", //【不帶欄目路徑】模塊欄目列表(分頁)(list-{dirname}-{page}.html)
"list-([A-za-z0-9 \-\_]+)\.html" => "index.php?c=category&dir=$1", //【不帶欄目路徑】模塊欄目列表(list-{dirname}.html)
"show-([0-9]+)\.html" => "index.php?c=show&id=$1", //【不帶欄目路徑】模塊內(nèi)容頁(show-{id}.html
"([A-za-z0-9 \-\_]+)\/p([0-9]+)\.html" => "index.php?c=category&dir=$1&page=$2", //【帶欄目路徑】模塊欄目列表(分頁)({dirname}/p{page}.html)
"([A-za-z0-9 \-\_]+)\/([0-9]+)\.html" => "index.php?c=show&id=$2", //【帶欄目路徑】模塊內(nèi)容頁({dirname}/{id}.html)
"([A-za-z0-9 \-\_]+)" => "index.php?c=category&dir=$1",
//【帶欄目路徑】模塊欄目列表({dirname})
//城市分站內(nèi)容
"([A-za-z0-9 \-\_]+)\/u([0-9]+)\/([0-9]+)\.html" => "index.php?c=show&id=$2&city=$1",
];
正則表達(dá)式技術(shù)不合格
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@迅??蚣苈?lián)合創(chuàng)始人
老師批評(píng)得是,感謝,已解決。