帝國cms的wap功能是一個實現手機版比較邊界且自由度高的方法,但這其中也有一些問題,就是地址只有動態地址,這樣對收錄似乎并不好。
這里我們以這套模板的wap端為例,來講一下帝國cms的wap端實現偽靜態的方法。
一、wap端模板的路徑
首先我們說明一下,wap端的模板是存儲在文件當中,地址為 /e/wap/template/ ,這其中有index.temp.php list.temp.php show.temp.php,分別對應首頁、列表頁、內容頁。
二、文件修改
我們打開index.temp.php文件,也就是首頁模板,其中list.php為列表頁鏈接,show.php為內容頁鏈接。
我們在第31行看到如下代碼:
1 | $classurl = "list.php?classid=" . $r [classid]. "&" . $wapstyle . "&bclassid=" . $bclassid ; |
其中classid即欄目id,style和bclassid對應模板樣式和父欄目id,這兩項可不填寫。
假設我們要把地址偽靜態為 /e/wap/list-8.html ,我們將上面的鏈接代碼修改為如下:
1 | $classurl = "list-" . $r [classid]. "html" ; |
其他地方類似,包含list鏈接的地方都修改為如上的方式。
接下來是內容頁鏈接地址,內容頁地址是在wap版靈動標簽中通過函數生成,函數在/e/wap/wapfun.php文件第527行,代碼如下:
1 | $titleurl = 'show.php?classid=' . $r [classid]. '&id=' . $r [id]. '&' . $wapstyle . '&bclassid=' . $class_r [ $r [classid]][bclassid]. '&cid=' . $r [classid]. '&cpage=0' ; |
我們也將其修改為靜態化的地址,這里需要注意,classid及id兩項為必須,其他可忽略:
1 | $titleurl = 'show-' . $r [classid]. '-' . $r [id]. '.html' ; |
上面是首頁及靈動標簽中地址的修改,接下來我們看列表頁,打開list.temp.php文件,其中的代碼與上面類似,修改方式可參考上方,例如第52行定義的內容頁地址:
1 | $titleurl = "show.php?classid=" . $r [classid]. "&id=" . $r [id]. "&" . $wapstyle . "&cpage=" . $page . "&cid=" . $classid . "&bclassid=" . $bclassid ; |
三、偽靜態規則
文件修改完之后,我們還需要相應的偽靜態規則來實現地址鏈接的rewrite,大家可根據自己的服務器環境選擇。
apache:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/e/wap/index.html$ $1/e/wap/index.php
RewriteRule ^(.*)/e/wap/list-([0-9]+).html$ $1/e/wap/list.php?classid=$2
RewriteRule ^(.*)/e/wap/show-([0-9]+)-([0-9]+).html$ $1/e/wap/show.php?classid=$2&id=$3
nginx:
location / {
rewrite ^(.*)/e/wap/index.html$ $1/e/wap/index.php
rewrite ^(.*)/e/wap/list-([0-9]+)/.html$ $1/e/wap/list.php?classid=$2
rewrite ^(.*)/e/wap/show-([0-9]+)-([0-9]+)/.html$ $1/e/wap/show.php?classid=$2&id=$3
}
新聞熱點
疑難解答