QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHPCMS

phpcms手机站模块实现自定义伪静态设置

 admin  2022-06-03 19:33:23
注意:我的手机模块本身就是二开过的,所以一下修改请你考虑自己的实际情况

一、后台模板修改部分
(1)打开phpcms\modules\wap\templates\m_edit.tpl.php在45行后边加入代码(m_add.tpl.php的45行处也加上):
  1.  
  2.     "100">开启伪静态: 
  3.     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';?> >开启 
  4.      
  5.     "weijingtai" style="width:100%;"
  6.     "100px" style="width:100px;">伪静态规则: 
  7.     class="y-bg">"text" class="input-text" name="setting[nohtml_list]" id="nohtml_list" size="50" value="{C}"/>

     
  8.     "text" class="input-text" name="setting[nohtml_show]" id="nohtml_show" size="50" value="{C}"/>
     
  9.     
     
  10.    "font-size:10px; color:#666666">list默认:list-{$typeid}-{$page}
     
  11.     show默认: show-{$catid}-{$typeid}-{$id}
     
  12.      
  13.      

效果:




二、源码部分修改

(1)打开phpcms\modules\wap\index.php修改如下:
  1. define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); 
改成:
  1. $setting = json_decode($this->wap['setting'], true); 
  2.         if($setting['nohtml']){ 
  3.             define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'] : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); 
  4.         }else
  5.             define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); 
  6.         } 

把:
  1. //构造wap url规则 
  2. define('URLRULE''index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}'); 
替换成:
  1. /*判断伪静态*/ 
  2.             $setting = json_decode($this->wap_site[$siteid]['setting'], true); 
  3.             //构造wap url规则 
  4.             if($setting['nohtml']){ 
  5.                 $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}-{$page}'
  6.                 if($setting['nohtml_list']){ 
  7.                     //$nohtml_list = str_replace("|","~",$setting['nohtml_list']); 
  8.                     //$nohtml_list = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$nohtml_list); 
  9.                     define('URLRULE', $nohtml_list.'.html'); 
  10.                 }else
  11.                    define('URLRULE''list-{$typeid}-{$page}.html'); 
  12.                 } 
  13.             }else
  14.                define('URLRULE''index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}'); 
  15.             } 


(2)修改phpcms\modules\wap\functions\global.func.php文件
把list_url方法里边的
  1. return WAP_SITEURL."&a=lists&typeid=$typeid";  
改成:
  1. /*判断开启伪静态*/ 
  2.     $dbs       = pc_base::load_model('wap_model'); 
  3.     $infos     = $dbs->select(); 
  4.     foreach($infos as $k => $info){ 
  5.         if($info['siteid'] == $siteid ){ 
  6.              $setting   = json_decode($infos[$k]['setting'], true); 
  7.         } 
  8.     }    
  9.     if(!array_key_exists('nohtml', $setting)){ 
  10.        $nohtml = 0; 
  11.     }else
  12.         $nohtml = trim($setting['nohtml']) ?  trim($setting['nohtml']) : 0; 
  13.     } 
  14. if($nohtml){ 
  15.         $page = 1; 
  16.         $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}-{$page}'
  17.         $nohtml_url = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$setting['nohtml_list']); 
  18.         return "/".$nohtml_url.'.html';//可以自定义伪静态 
  19.     }else
  20.         return WAP_SITEURL."&a=lists&typeid=$typeid";  
  21.     } 


show_url方法中做同样修改
  1. return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";  
替换成:
  1. /*判断开启伪静态*/ 
  2. $siteid = $GLOBALS['siteid']; 
  3. $dbs       = pc_base::load_model('wap_model'); 
  4. $infos     = $dbs->select(); 
  5. foreach($infos as $k => $info){ 
  6.     if($info['siteid'] == $siteid ){ 
  7.          $setting   = json_decode($infos[$k]['setting'], true); 
  8.     } 
  9. }    
  10. if(!array_key_exists('nohtml', $setting)){ 
  11.    $nohtml = 0; 
  12. }else
  13.     $nohtml = trim($setting['nohtml']) ?  trim($setting['nohtml']) : 0; 
  14.  
  15. if($nohtml){ 
  16.     $html_show = trim($setting['nohtml_show']) ? trim($setting['nohtml_show']) :'show-{$catid}-{$typeid}-{$id}-1'
  17.     $html_show  = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_show); 
  18.     return "/".$html_show.'.html'
  19. }else
  20.    return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";  
并且并强烈建议新增一个调用某个栏目url的函数
  1. /* 
  2.  *  新增  获取当前页面的栏目的url 
  3.  *  typeid 栏目id 
  4.  */  
  5. function caturl($typeid) { 
  6.     if(!empty($typeid)){ 
  7.         /*判断开启伪静态*/ 
  8.         if (empty($siteid)) $siteid = $GLOBALS['siteid']; 
  9.         $dbs       = pc_base::load_model('wap_model'); 
  10.         $infos     = $dbs->select(); 
  11.         foreach($infos as $k => $info){ 
  12.             if($info['siteid'] == $siteid ){ 
  13.                  $setting   = json_decode($infos[$k]['setting'], true); 
  14.             } 
  15.         }    
  16.         if(!array_key_exists('nohtml', $setting)){ 
  17.            $nohtml = 0; 
  18.         }else
  19.             $nohtml = trim($setting['nohtml']) ?  trim($setting['nohtml']) : 0; 
  20.         } 
  21.  
  22.         if($nohtml){ 
  23.             $page = 1;
  24.             $html_list = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']) :'list-{$typeid}-{$page}'
  25.             $html_list  = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_list); 
  26.             return "/".$html_list.'.html'
  27.         }else
  28.            return WAP_SITEURL."&a=lists&typeid=$typeid"
  29.         } 
  30.          
  31.     }else
  32.        return WAP_SITEURL; 
  33.     } 
这样我们就可以直接调用{caturl(7)}的栏目链接,而无需关心伪静态开启还是关闭。

另外由于默认的伪静态路径和pc站的伪静态路径,所以设置伪静态规则的时候一定要先判断一下
我用的是nginx,伪静态写法为:
  1. location / { 
  2.     if ($host = 'm.tengcee.com' ) { 
  3.     rewrite ^(.*)/list-([0-9]+)-([0-9]+)\.html$ $1/index.php?&a=lists&typeid=$2&page=$3; 
  4.     rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?&a=show&catid=$2&typeid=$3&id=$4; 
  5.     } 
  6.     rewrite ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4; 
  7.     rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4; 
  8.     rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=lists&catid=$2&page=$3; 
appach写法:
 
  1. RewriteEngine on 
  2. RewriteRule ^content-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 
  3. RewriteRule ^show-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 
  4. RewriteRule ^list-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=lists&catid=$1&page=$2 
  5.  
  6. # 绑定m.pweb123.com 
  7. RewriteCond %{HTTP_HOST} ^m\.pweb123\.com$ [NC] 
  8. RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=wap&c=index&a=lists&typeid=$2&page=$3; 
  9. RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?&a=show&catid=$2&typeid=$3&id=$4; 


以上就是全部教程,有想测试的可以去测试,有什么问题请及时反馈给我,谢谢!




¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《phpcms手机站模块实现自定义伪静态设置》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/cms/phpcms/744.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有0条评论
点击图片更换

添加微信好友

添加微信好友

微信小程序

百度小程序