一、后台模板修改部分
(1)打开phpcmsmoduleswaptemplatesm_edit.tpl.php在45行后边加入代码(m_add.tpl.php的45行处也加上):
"100" >开启伪静态:class ="y-bg">"radio" name="setting[nohtml]" value="0" id="nohtml" if (!$nohtml) echo 'checked';?>>关闭 "radio" name="setting[nohtml]" value="1" id="nohtml" if ($nohtml) echo 'checked';?> >开启"weijingtai" style="width:100%;">"100px" style="width:100px;">伪静态规则:class ="y-bg">"text" class="input-text" name="setting[nohtml_list]" id="nohtml_list" size="50" value="{C}"/>
- "text" class="input-text" name="setting[nohtml_show]" id="nohtml_show" size="50" value="{C}"/>
- "font-size:10px; color:#666666">list默认:list-{$typeid}-{$page}
- show默认: show-{$catid}-{$typeid}-{$id}
效果:
二、源码部分修改
(1)打开phpcmsmoduleswapindex.php修改如下:
改成:
- define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);
- $setting = json_decode($this->wap['setting'], true);
- if($setting['nohtml']){
- define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'] : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);
- }else{
- define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);
- }
把:
替换成:
- //构造wap url规则
- define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');
- /*判断伪静态*/
- $setting = json_decode($this->wap_site[$siteid]['setting'], true);
- //构造wap url规则
- if($setting['nohtml']){
- $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}-{$page}';
- if($setting['nohtml_list']){
- //$nohtml_list = str_replace("|","~",$setting['nohtml_list']);
- //$nohtml_list = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$nohtml_list);
- define('URLRULE', $nohtml_list.'.html');
- }else{
- define('URLRULE', 'list-{$typeid}-{$page}.html');
- }
- }else{
- define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');
- }
(2)修改phpcmsmoduleswapfunctionsglobal.func.php文件
把list_url方法里边的
改成:
- return WAP_SITEURL."&a=lists&typeid=$typeid";
- /*判断开启伪静态*/
- $dbs = pc_base::load_model('wap_model');
- $infos = $dbs->select();
- foreach($infos as $k => $info){
- if($info['siteid'] == $siteid ){
- $setting = json_decode($infos[$k]['setting'], true);
- }
- }
- if(!array_key_exists('nohtml', $setting)){
- $nohtml = 0;
- }else{
- $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0;
- }
- if($nohtml){
- $page = 1;
- $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}-{$page}';
- $nohtml_url = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$setting['nohtml_list']);
- return "/".$nohtml_url.'.html';//可以自定义伪静态
- }else{
- return WAP_SITEURL."&a=lists&typeid=$typeid";
- }
show_url方法中做同样修改
替换成:
- return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";
并且并强烈建议新增一个调用某个栏目url的函数
- /*判断开启伪静态*/
- $siteid = $GLOBALS['siteid'];
- $dbs = pc_base::load_model('wap_model');
- $infos = $dbs->select();
- foreach($infos as $k => $info){
- if($info['siteid'] == $siteid ){
- $setting = json_decode($infos[$k]['setting'], true);
- }
- }
- if(!array_key_exists('nohtml', $setting)){
- $nohtml = 0;
- }else{
- $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0;
- }
- if($nohtml){
- $html_show = trim($setting['nohtml_show']) ? trim($setting['nohtml_show']) :'show-{$catid}-{$typeid}-{$id}-1';
- $html_show = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_show);
- return "/".$html_show.'.html';
- }else{
- return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";
- }
这样我们就可以直接调用{caturl(7)}的栏目链接,而无需关心伪静态开启还是关闭。
- /*
- * 新增 获取当前页面的栏目的url
- * typeid 栏目id
- */
- function caturl($typeid) {
- if(!empty($typeid)){
- /*判断开启伪静态*/
- if (empty($siteid)) $siteid = $GLOBALS['siteid'];
- $dbs = pc_base::load_model('wap_model');
- $infos = $dbs->select();
- foreach($infos as $k => $info){
- if($info['siteid'] == $siteid ){
- $setting = json_decode($infos[$k]['setting'], true);
- }
- }
- if(!array_key_exists('nohtml', $setting)){
- $nohtml = 0;
- }else{
- $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0;
- }
- if($nohtml){
- $page = 1;
- $html_list = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']) :'list-{$typeid}-{$page}';
- $html_list = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_list);
- return "/".$html_list.'.html';
- }else{
- return WAP_SITEURL."&a=lists&typeid=$typeid";
- }
- }else{
- return WAP_SITEURL;
- }
- }
另外由于默认的伪静态路径和pc站的伪静态路径,所以设置伪静态规则的时候一定要先判断一下
我用的是nginx,伪静态写法为:
appach写法:
- location / {
- if ($host = 'm.tengcee.com' ) {
- rewrite ^(.*)/list-([0-9]+)-([0-9]+).html$ $1/index.php?&a=lists&typeid=$2&page=$3;
- rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index.php?&a=show&catid=$2&typeid=$3&id=$4;
- }
- rewrite ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4;
- rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4;
- rewrite ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index.php?m=content&c=index&a=lists&catid=$2&page=$3;
- }
- RewriteEngine on
- RewriteRule ^content-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3
- RewriteRule ^show-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3
- RewriteRule ^list-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=lists&catid=$1&page=$2
- # 绑定m.pweb123.com
- RewriteCond %{HTTP_HOST} ^m.pweb123.com$ [NC]
- RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index.php?m=wap&c=index&a=lists&typeid=$2&page=$3;
- RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index.php?&a=show&catid=$2&typeid=$3&id=$4;
以上就是全部教程,有想测试的可以去测试,有什么问题请及时反馈给我,谢谢!