电脑版静态效果:
http://www.xxx.cn/view/
http://www.xxx.cn/view/3414.html
移动版伪静态效果:
http://m.xxx.cn/view/
http://m.xxx.cn/view/3414.html
修改或者覆盖文件之前请备份以下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.xxx.com
所属组:站点设置
变量名称:cfg_rewritem
变量类型:布尔(Y/N)
参数说明:手机版伪静态
变量值:Y
所属组:站点设置
3.\m\index.php 修改成永远是动态,不生成index.html
把里面的:
$row['showmod'] = isset($row['showmod'])? $row['showmod'] : 0; if ($row['showmod'] == 1) { $pv->SaveToHtml(dirname(__FILE__).'/index.html'); include(dirname(__FILE__).'/index.html'); exit(); } else { $pv->Display(); exit(); }
替换成:
$pv->Display(); exit();
4.\m\list.php 增加伪静态判断
把里面的:
$tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
替换成:
if($cfg_rewritem == 'Y') { $typedir = parse_url($tid, PHP_URL_PATH); $PageNo = stripos(GetCurUrl(), '.html') ? intval(str_replace('.html', '', end(explode("_", GetCurUrl())))) : 1; $tinfos = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE typedir='/$typedir' or typedir='{cmspath}/$typedir'"); if(is_array($tinfos)) { $tid = $tinfos['id']; $typeid = GetSonIds($tid); $row = $dsql->GetOne("Select count(id) as total From `#@__archives` where typeid in({$typeid})"); $TotalResult = is_array($row) ? $row['total'] : 0; } else { $tid = 0; } } else { $tid = (isset($tid) && is_numeric($tid) ? $tid : 0); }
5.\m\view.php 增加伪静态判断
在:
$t1 = ExecTime();
下面加入:
if($cfg_rewritem == 'Y') { $aid = stripos(GetCurUrl(), '.html') ? intval(str_replace('.html', '', end(explode("/", GetCurUrl())))) : 0; }
6.\include\arc.listview.class.php 增加移动版伪静态分页功能,找到
global $cfg_rewrite;
替换成:
global $cfg_rewrite,$cfg_rewritem;
继续查找:
$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&"; $purl .= '?'.$geturl;
替换成:
if($cfg_rewritem == 'Y') { $purl = ""; } else { $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&"; $purl .= '?'.$geturl; }
继续查收:
return $plist;
在它的上面加入:
if($cfg_rewritem == 'Y') { $plist = preg_replace("/PageNo=(\d+)/i",'list_'.$this->TypeID.'_\\1.html',$plist); }
7.\include\typelink.class.php 修改移动版{dede:field name=’position’/}伪静态,找到
$indexpage = "<a href='index.php'>".$this->indexName."</a>";
替换成:
if($GLOBALS['cfg_rewritem'] == 'Y') { $indexpage = "<a href='".$GLOBALS['cfg_mobile']."'>".$this->indexName."</a>"; } else { $indexpage = "<a href='index.php'>".$this->indexName."</a>"; }
继续查找:
return 'list.php?tid='.$typeinfos['id'];
替换成:
if($GLOBALS['cfg_rewritem'] == 'Y') { return GetTypeUrl($typeinfos['id'],MfTypedir($typeinfos['typedir']),$typeinfos['isdefault'],$typeinfos['defaultname'],$typeinfos['ispart'],$typeinfos['namerule2'],$typeinfos['moresite'],$typeinfos['siteurl'],$typeinfos['sitepath']); } else { return 'list.php?tid='.$typeinfos['id']; }
8.移动版模板中使用标签
{dede:global.cfg_mobile/} http://m.xxx.com
[field:global.cfg_basehost/][field:litpic/]
图片用主站的,如:http://www.xx.com/uploads/allimg/180105/20493W4S-0.jpg
{dede:field.body/}
改成
{dede:field.body runphp=yes} global $cfg_basehost; $str = @me; $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search2 = '#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i'; $search3 = '#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i'; $content = preg_replace($search,'$1$3',$str); $content = preg_replace($search1,'$1$3',$content); $content = preg_replace($search2,'$1$2',$content); $content = preg_replace($search3,'$1$2',$content); @me = $content; @me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content); {/dede:field.body}
栏目内容 {dede:field.content/}
{dede:field.content runphp=yes} global $cfg_basehost; $str = @me; $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is'; $search2 = '#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i'; $search3 = '#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i'; $content = preg_replace($search,'$1$3',$str); $content = preg_replace($search1,'$1$3',$content); $content = preg_replace($search2,'$1$2',$content); $content = preg_replace($search3,'$1$2',$content); @me = $content; @me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content); {/dede:field.content}
index.php 改成 {dede:global.cfg_mobile/}
list.php?tid=[field:id/] 改成 [field:typelink/]
list.php?tid=~id~ 改成 ~typelink~
list.php?tid={dede:field name=’id’/} 改成 {dede:field.typeurl/}
view.php?aid=[field:id/] 改成 [field:arcurl/]
[field:litpic/] 改成 [field:global.cfg_basehost/][field:litpic/]
[field:image/] 改成 <img src=”[field:global.cfg_basehost/][field:litpic/]”>
上一页标签 {dede:prenext get=’pre’/}
{dede:prenext get=pre runphp=yes} $preurl = @me; preg_match('/aid=(\d*)/',$preurl,$match); $result = GetOneArchive($match[1]); @me = !empty($result) ? "上一篇:<a href=\"{$result['arcurl']}\">{$result['title']}</a>" : "上一篇:没有了"; {/dede:prenext}
下一页标签 {dede:prenext get=’next’/}
{dede:prenext get=next runphp=yes} $preurl = @me; preg_match('/aid=(\d*)/',$preurl,$match); $result = GetOneArchive($match[1]); @me = !empty($result) ? "下一篇:<a href=\"{$result['arcurl']}\">{$result['title']}</a>" : "下一篇:没有了"; {/dede:prenext}
9.移动版伪静态规则
apache .htaccess 放到m文件夹下
#dedecms移动版伪静态 RewriteEngine On RewriteBase / #移动版列表栏目 RewriteRule ^(.*)/$ /list.php?tid=$1 #移动版列表栏目分页 RewriteRule ^(.*)/list_([0-9]+)_([0-9]+)\.html$ /list.php?tid=$1&PageNo=$2 #移动版文章页伪静态规则 RewriteRule ^(.*)/([0-9]+)\.html$ /view.php?aid=$1
Nginx 放到m文件夹下
# RewriteBase / #移动版列表栏目 rewrite ^/(.*)/$ /list.php?tid=$1; #移动版列表栏目分页 rewrite ^/(.*)/list_([0-9]+)_([0-9]+)\.html$ /list.php?tid=$1&PageNo=$2; #移动版文章页伪静态规则 rewrite ^/(.*)/([0-9]+)\.html$ /view.php?aid=$1;
10.电脑版跳转到移动版代码
1)首页
<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobile/}"> <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)列表
<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobile/}{dede:type}[field:typeurl/]{/dede:type}"> <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:type}[field:typeurl/]{/dede:type}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
3)内容
<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}"> <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>
大功告成!
原创文章,作者:管理员,如若转载,请注明出处:http://www.bajiege.com/archives/837.html