织梦DedeCMS>正文
dedecms织梦移动版伪静态 - 实现与PC电脑版静态地址url一致教程+伪静态规则
2018-04-10 11:35电脑版静态效果
移动版伪静态效果
以下教程所修改的文件(utf8/gbk)打包下载:
修改或者覆盖文件之前请备份以下4个文件
mindex.php
mlist.php
mview.php
includearc.listview.class.php
下载链接:
电脑版静态生成这里就不多说了,移动版伪静态操作教程如下:
1.移动版域名 m.123.com 解析并指向绑定目录到网站目录的m文件夹
2.后台-系统配置 添加变量 (为了使用绝对路径,使用电脑版的文章图片,为了移动版模板css、js、images使用绝对路径)
变量名称:cfg_mobile
变量类型:文本
参数说明:手机版网址
变量值:http://m.123.com
所属组:站点设置
变量名称:cfg_rewritem
变量类型:布尔(Y/N)
参数说明:手机版伪静态
变量值:Y
所属组:站点设置
栏目列表【文件保存目录】可以是以下形式
3.mindex.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->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row[‘templet‘]);
$pv->Display();
exit();
4.mlist.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.mview.php 增加伪静态判断
在
$t1 = ExecTime();
下面加入
if($cfg_rewritem == ‘Y‘)
{
$aid = stripos(GetCurUrl(), ‘.html‘) ? intval(str_replace(‘.html‘, ‘‘, end(explode("/", GetCurUrl())))) : 0;
}
6.includearc.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.移动版模板中使用标签有
{dede:global.cfg_mobile/} http://m.123.com
[field:global.cfg_basehost/][field:litpic/]
图片用主站的,如:http://www.123.com/uploads/allimg/170513/20493W4S-0.jpg
{dede:field.body/}
改成
{dede:field.body runphp=yes}
global $cfg_basehost;
$str = @me;
$search = ‘/(<img.*?)width=(["‘])?.*?(?(2)2|s)([^>]+>)/is‘;//过滤img里的width
$search1 = ‘/(<img.*?)height=(["‘])?.*?(?(2)2|s)([^>]+>)/is‘;//过滤img里的height
$search2 = ‘#(<img.*?style=".*?)width:d+px;([^"]*?.*?>)#i‘;//过滤img里style的width
$search3 = ‘#(<img.*?style=".*?)height:d+px;([^"]*?.*?>)#i‘;//过滤img里style的height
$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}
其他标签跟电脑版一样
8.移动版伪静态规则 apache
.htaccess 放到m文件夹下
注意栏目【列表命名规则】要对应伪静态栏目分页规则和includearc.listview.class.php里面的分页规则。
#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
完成。
本文链接:https://www.0937.biz/post-297.html
猜你喜欢
- 2018-04-10 织梦安装后提示Function ereg_replace() is deprecated的解决方法
- 2018-04-10 dede数据库批量替换栏目页和内容页标题、关键字、描述
- 2018-04-10 dedecms修改栏目信息报错“保存当前栏目更改时失败,请检查你的输入资料是否存在问题!”
- 2018-04-10 DEDECMS 5.6转5.7数据库升级SQL命令
- 2018-04-10 dedecms指定栏目内关键词替换SQL
- 2018-04-10 DedeCMSV57数据库结构文档
- 2018-04-10 织梦title字数限制的两种方法
- 2018-04-10 dedecms管理员密码重置工具radminpass.php
- 2018-04-10 织梦漏洞文件
- 图文推荐
-
- 热门标签