找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5547|回复: 1

[分享] dedecms织梦移动版伪静态 - 实现与PC电脑版静态地址url一致教程+伪静态规则

[复制链接]
发表于 2018-8-4 15:17:07 | 显示全部楼层 |阅读模式 来自 河南省新乡市
移动版伪静态效果
1.jpg


修改以下4个文件
\m\index.php
\m\list.php
\m\view.php
\include\arc.listview.class.php

电脑版静态生成这里就不多说了,移动版伪静态操作教程如下:

1.移动版域名 m.123.com 解析并指向绑定目录到网站目录的m文件夹


2.后台-系统配置 添加变量 (为了使用绝对路径,使用电脑版的文章图片,为了移动版模板css、js、images使用绝对路径)

变量名称:cfg_mobile
变量类型:文本
参数说明:手机版网址
变量值:http://m.123.com
所属组:站点设置

变量名称:cfg_rewritem
变量类型:布尔(Y/N)
参数说明:手机版伪静态
变量值:Y
所属组:站点设置

2.png

栏目列表【文件保存目录】可以是以下形式
3.png



3.\m\index.php 修改成永远是动态,不生成index.html
把里面的
  1. $row[‘showmod‘] = isset($row[‘showmod‘])? $row[‘showmod‘] : 0;
  2. if ($row[‘showmod‘] == 1)
  3. {
  4.     $pv->SaveToHtml(dirname(__FILE__).‘/index.html‘);
  5.     include(dirname(__FILE__).‘/index.html‘);
  6.     exit();
  7. } else {
  8.     $pv->Display();
  9.     exit();
  10. }
复制代码

改成

  1. $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row[‘templet‘]);
  2. $pv->Display();
  3. exit();
复制代码


4.\m\list.php 增加伪静态判断
把里面的

  1. $tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
复制代码

改成
  1. if($cfg_rewritem == ‘Y‘)
  2. {
  3.     $typedir = parse_url($tid, PHP_URL_PATH);
  4.     $PageNo = stripos(GetCurUrl(), ‘.html‘) ? intval(str_replace(‘.html‘, ‘‘, end(explode("_", GetCurUrl())))) : 1;
  5.     $tinfos = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE typedir=‘/$typedir‘ or typedir=‘{cmspath}/$typedir‘");

  6.     if(is_array($tinfos))
  7.     {
  8.         $tid = $tinfos[‘id‘];
  9.         $typeid = GetSonIds($tid);
  10.         $row = $dsql->GetOne("Select count(id) as total From `dede_archives` where typeid in({$typeid})");
  11.         $TotalResult = is_array($row) ? $row[‘total‘] : 0;
  12.     }
  13.     else
  14.     {
  15.         $tid = 0;
  16.     }
  17. }
  18. else
  19. {
  20.     $tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
  21. }
复制代码

5.\m\view.php 增加伪静态判断

  1. $t1 = ExecTime();
复制代码

下面加入

  1. if($cfg_rewritem == ‘Y‘)
  2. {
  3.     $aid = stripos(GetCurUrl(), ‘.html‘) ? intval(str_replace(‘.html‘, ‘‘, end(explode("/", GetCurUrl())))) : 0;
  4. }
复制代码


6.\include\arc.listview.class.php 增加移动版伪静态分页功能,找到

  1. global $cfg_rewrite;
复制代码

改成

  1. global $cfg_rewrite,$cfg_rewritem;
复制代码

继续找到

  1. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  2. $purl .= ‘?‘.$geturl;
复制代码

改成
  1. if($cfg_rewritem == ‘Y‘)
  2. {
  3.     $purl = "";
  4. }
  5. else
  6. {
  7.     $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  8.     $purl .= ‘?‘.$geturl;
  9. }

复制代码

继续找到下面的

  1. return $plist;
复制代码

在它的上面加入

  1. if($cfg_rewritem == ‘Y‘)
  2. {
  3.     $plist = preg_replace("/PageNo=(\d+)/i",‘list_‘.$this->TypeID.‘_\\1.html‘,$plist);
  4. }
复制代码

7.移动版模板中使用标签有

{dede:global.cfg_mobile/}    http://m.123.com

[field:global.cfg_basehost/][field:litpic/]    图片用主站的,如:
{dede:field.body/}

改成
  1. {dede:field.body runphp=yes}
  2. global $cfg_basehost;
  3. $str = @me;
  4. $search = ‘/(<img.*?)width=(["\‘])?.*?(?(2)\2|\s)([^>]+>)/is‘;//过滤img里的width
  5. $search1 = ‘/(<img.*?)height=(["\‘])?.*?(?(2)\2|\s)([^>]+>)/is‘;//过滤img里的height
  6. $search2 = ‘#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i‘;//过滤img里style的width
  7. $search3 = ‘#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i‘;//过滤img里style的height
  8. $content = preg_replace($search,‘$1$3‘,$str);
  9. $content = preg_replace($search1,‘$1$3‘,$content);
  10. $content = preg_replace($search2,‘$1$2‘,$content);
  11. $content = preg_replace($search3,‘$1$2‘,$content);
  12. @me = $content;
  13. @me = str_replace(‘/uploads/allimg/‘, $cfg_basehost.‘/uploads/allimg/‘, $content);//手机版图片使用绝对路径
  14. {/dede:field.body}
复制代码


其他标签跟电脑版一样

8.移动版伪静态规则 apache

.htaccess  放到m文件夹下

注意栏目【列表命名规则】要对应伪静态栏目分页规则和\include\arc.listview.class.php里面的分页规则。

4.png
  1. #[url=http://bbs.piaoxian.net/forum-23-1.html]dedecms[/url]移动版伪静态
  2. RewriteEngine On
  3. RewriteBase /

  4. #移动版列表栏目
  5. RewriteRule ^(.*)/$ /list.php?tid=$1
  6. #移动版列表栏目分页
  7. RewriteRule ^(.*)/list_([0-9]+)_([0-9]+)\.html$ /list.php?tid=$1&PageNo=$2
  8. #移动版文章页伪静态规则
  9. RewriteRule ^(.*)/([0-9]+)\.html$ /view.php?aid=$1
复制代码


9.电脑版跳转到移动版代码

1)首页

  1. <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobile/}">
  2. <script type="text/javascript">if(window.location.toString().indexOf(‘pref=padindex‘) != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobile/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
复制代码


2)列表

  1. <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}{dede:type}[field:typeurl/]{/dede:type}">
  2. <script type="text/javascript">if(window.location.toString().indexOf(‘pref=padindex‘) != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}{dede:type}[field:typeurl/]{/dede:type}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
复制代码


3)内容

  1. <meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobile/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result[‘arcurl‘];{/dede:field.id}">
  2. <script type="text/javascript">if(window.location.toString().indexOf(‘pref=padindex‘) != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobile/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result[‘arcurl‘];{/dede:field.id}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
复制代码

完成

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

发表于 2018-8-16 10:05:52 | 显示全部楼层 来自 广东省广州市
厉害! 我基本都是直接删除了M文件夹,单独建套手机站模板,然后生成!

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-4-27 01:24 , Processed in 0.049256 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表