1. 程式人生 > >dedecms織夢移動版偽靜態 - 實現與PC電腦版靜態地址url一致教程+偽靜態規則

dedecms織夢移動版偽靜態 - 實現與PC電腦版靜態地址url一致教程+偽靜態規則

intval 使用 nokia 說明 one 之前 列表 exit 技術

電腦版靜態效果

技術分享


移動版偽靜態效果

技術分享


以下教程所修改的文件(utf8/gbk)打包下載:

修改或者覆蓋文件之前請備份以下4個文件
\m\index.php
\m\list.php
\m\view.php
\include\arc.listview.class.php

鏈接: https://pan.baidu.com/s/1i49ABe1 密碼: 2wid

電腦版靜態生成這裏就不多說了,移動版偽靜態操作教程如下:

1.移動版域名 m.123.com 解析並指向綁定目錄到網站目錄的m文件夾


2.後臺-系統配置 添加變量 (為了使用絕對路徑,使用電腦版的文章圖片,為了移動版模板css、js、images使用絕對路徑)


變量名稱:cfg_mobile
變量類型:文本
參數說明:手機版網址
變量值:http://m.123.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->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row[‘templet‘]);
$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.移動版模板中使用標簽有
{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文件夾下

技術分享

註意欄目【列表命名規則】要對應偽靜態欄目分頁規則和\include\arc.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



9.電腦版跳轉到移動版代碼


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_mobileurl/}{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_mobileurl/}{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>


完成。

dedecms織夢移動版偽靜態 - 實現與PC電腦版靜態地址url一致教程+偽靜態規則