温馨提醒

如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢

本文最后更新于2023年8月29日,已超过 180天没有更新

此教程适合文章命名规则选择的是{aid},伪静态设置成功后,访问URL地址效果如下。

电脑端的URL地址:

列表页http://www.123.com/news/
列表分页http://www.123.com/news/list_1_2.html
内容页http://www.123.com/xinwenzixun/6.html
内容页分页http://www.123.com/news/6_2.html
TAG标签页http://www.123.com/tags/职场/
TAG标签分页http://www.123.com/tags/职场/2/
搜索页http://www.123.com/search/职场.html
搜索页分页http://www.123.com/search/职场-2.html

手机端的URL地址:

列表页http://m.123.com/news/
列表分页http://m.123.com/news/list_1_2.html
内容页http://m.123.com/news/6.html
内容页分页http://m.123.com/xinwenzixun/6_2.html
TAG标签页http://m.123.com/tags/职场/
TAG标签分页http://m.123.com/tags/职场/2/
搜索页http://m.123.com/search/职场.html
搜索页分页http://m.123.com/search/职场-2.htm

是不是心动了呢,那我们开始动手设置吧。

准备工作:先备份好网站数据,网站需要修改的文件我已打包好,都是从官网上直接下载,然后修改的,下载后选择自己网站编码对应的文件,然后覆盖以前的即可。把你的移动域名解析到网站并绑定网站根目录下的m文件夹。点击下载文件

如果你想自己修改文件,上面的下载请忽略,然后查看下面的修改教程。

一、后台-系统参数-核心设置

是否使用伪静态-选择是
(是/否)支持多站点,开启此项后附件、栏目连接、arclist内容启用绝对网址-选择否

二、安装全站动静态插件,下载的压缩包里有。设置全站为动态。

三、后台添加两个新变量:

变量名称:cfg_mobile
变量类型:文本
参数说明:手机版网址
变量值:你的手机站网址 例如:http://m.abc.com
所属组:站点设置
变量名称:cfg_rewritem
变量类型:布尔(Y/N)
参数说明:手机版伪静态
变量值:Y
所属组:站点设置

四、修改文件

1、列表页和内容页伪静态链接

打开 /plus/list.php 搜索

$tid = (isset($tid) && is_numeric($tid) ? $tid : 0);

修改为(dede表前缀换成你自己的)

if($cfg_rewrite == 'Y')
{     if(!is_numeric($tid))
    {
        $typedir = parse_url($tid, PHP_URL_PATH);
        $PageNo = stripos(GetCurUrl(), '.html') ? intval(str_replace('.html', '', end(explode("_", GetCurUrl())))) : 1;
        $tinfos = $dsql->GetOne("SELECT * FROM `dede_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 `dede_archives` where typeid in({$typeid})");
        }
        else
        {
            $tid = 0;
        }
    }
}
else
{
    $tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
}

打开 /plus/view.php 搜索

$t1 = ExecTime();

在它下面加入

if($cfg_rewrite == 'Y')
{
    if(!is_numeric($aid))
    {
        $aid = stripos(GetCurUrl(), '.html') ? str_replace('.html', '', end(explode("/", GetCurUrl()))) : 0;
        $aidpage = explode("_",$aid);
        $aid = intval($aidpage[0]);
        $pageno = intval($aidpage[1]);
    }
}

打开 /include/arc.listview.class.php 搜索

//获得上一页和下一页的链接

在它上面加入

if($cfg_rewrite == 'Y')
{
    $purl = "";
}
else
{
    $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
    $purl .= '?'.$geturl;
}

继续搜索

$plist = str_replace('.php?tid=', '-', $plist);

在它上面加上

$tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
$tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
$plist = preg_replace("/PageNo=(\d+)/i",str_replace("{page}","\\1",$tnamerule),$plist);

打开 /include/helpers/channelunit.helper.php 搜索

global $cfg_typedir_df;

修改为

global $cfg_typedir_df, $cfg_rewrite;

继续搜索

$reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;

修改为

if($cfg_rewrite == 'Y')
{
    $reurl = $typedir.'/';
}
else
{
    //动态
    $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
}

继续搜索

return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';

修改为

$articleDir = MfTypedir($typedir);
$articleRule = strtolower($namerule);
if($articleRule=='')
{
    $articleRule = strtolower($GLOBALS['cfg_df_namerule']);
}
if($typedir=='')
{
    $articleDir  = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
}
$dtime = GetDateMk($timetag);
list($y, $m, $d) = explode('-', $dtime);
$arr_rpsource = array('{typedir}','{y}','{m}','{d}','{timestamp}','{aid}','{cc}');
$arr_rpvalues = array($articleDir,$y, $m, $d, $timetag, $aid, dd2char($m.$d.$aid.$y));
if($filename != '')
{
    $articleRule = dirname($articleRule).'/'.$filename.$GLOBALS['cfg_df_ext'];
}
$articleRule = str_replace($arr_rpsource,$arr_rpvalues,$articleRule);
if(preg_match("/\{p/", $articleRule))
{
    $articleRule = str_replace('{pinyin}',GetPinyin($title).'_'.$aid,$articleRule);
    $articleRule = str_replace('{py}',GetPinyin($title,1).'_'.$aid,$articleRule);
}
$articleUrl = '/'.preg_replace("/^\//", '', $articleRule);
if(preg_match("/index\.html/", $articleUrl) && $cfg_arc_dirname=='Y')
{
    $articleUrl = str_replace('index.html', '', $articleUrl);
}
return $articleUrl;

2、内容文章分页伪静态

打开 /include/arc.archives.class.php 搜索

$PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);

有2处,修改为

$PageList = preg_replace("#view.php\?aid=(\d+)#i", '\\1.html', $PageList);

继续搜索

$PageList = str_replace(".php?aid=", "-", $PageList);

有3处,修改为

$PageList = str_replace("view.php?aid=", "", $PageList);

继续搜索

$PageList =  preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);

有3处,修改为

$PageList =  preg_replace("#&pageno=(\d+)#i", '_\\1.html', $PageList);

3、TAG标签伪静态链接

打开 /include/taglib/tag.lib.php 搜索

$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";

修改为

$row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";

4、TAG标签分页伪静态链接

打开 /include/arc.taglist.class.php 搜索

$this->PageNo = $GLOBALS['PageNo'];

在它下面加入

if($this->PageNo == 0)
{
    $this->PageNo = 1;
}

继续搜索

$prepage="";

在它上面加入

global $cfg_rewrite;

继续搜索

$purl .= "?/".urlencode($this->Tag);

修改为

if($cfg_rewrite == 'Y')
{
    $purl = "/tags/".urlencode($this->Tag);
}
else
{
    $purl .= "?/".urlencode($this->Tag);
}

搜索:

$listdd.="<li><a href='".$purl."/$j/'>".$j."</a></li>\r\n";

替换成:

$listdd.="<li><a href='".$purl."/$j.html'>".$j."</a></li>\r\n";

搜索:

$indexpage="<li><a href='".$purl."/1/'>首页</a></li>\r\n";

替换成:

$indexpage="<li><a href='".$purl."/1.html'>首页</a></li>\r\n";

搜索:

$prepage.="<li><a href='".$purl."/$prepagenum/'>上一页</a></li>\r\n";

替换成:

$prepage.="<li><a href='".$purl."/$prepagenum.html'>上一页</a></li>\r\n";

搜索:

$nextpage.="<li><a href='".$purl."/$nextpagenum/'>下一页</a></li>\r\n";

替换成:

$nextpage.="<li><a href='".$purl."/$nextpagenum.html'>下一页</a></li>\r\n";

搜索:

$endpage="<li><a href='".$purl."/$totalpage/'>末页</a></li>\r\n";

替换成:

$endpage="<li><a href='".$purl."/$totalpage.html'>末页</a></li>\r\n";

5、搜索页伪静态链接

打开 /plus/search.php 搜索

$mid = (isset($mid) && is_numeric($mid)) ? $mid : 0;

在它下面加入

if ( $mobile==1 )
{
    define('DEDEMOB', 'Y');
}

继续搜索

$t1 = ExecTime();

在它下面加入

$keyword = preg_replace("/-(\d+)/i",'',$keyword);
$oldkeyword = preg_replace("/-(\d+)/i",'',$oldkeyword);

打开 /include/arc.searchview.class.php 搜索

global $oldkeyword;

修改为

global $oldkeyword, $cfg_rewrite;

继续搜索

$purl .= "?".$geturl;

修改为

if($cfg_rewrite != 'Y' && !defined('DEDEMOB'))
{
    $purl .= "?".$geturl;
}
else
{
    $purl = '/search/'.urlencode($oldkeyword);
}

继续搜索

return $plist;

修改为

if($cfg_rewrite == 'Y')
{
    $plist = preg_replace("/PageNo=(\d+)/i",'-\\1.html',$plist);
}
return $plist;

6、移动版当前位置 {dede:field.position/} 标签动态改成伪静态

打开 /include/typelink.class.php 搜索

$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'];
}

7、模板里把搜索框代码改成静态的js提交搜索,参考下面代码,注意网址换成你自己的

电脑端

<script type="text/javascript">
    function search()
    {
        var q = document.getElementById("q").value;
        window.location.href = "http://www.abc.com/search/"+q+".html";
    }
    function enterIn(obj,evt)
    {
        var evt = evt ? evt : (window.event ? window.event : null);
        if (evt.keyCode == 13)
        {
            var q = obj.value;
            window.location.href = "http://www.abc.com/search/"+q+".html";
        }
    }
</script>

<form action="" method="post" onsubmit="return false">
        <div class="form">
            <h4>搜索</h4>
            <input name="q" id="q" onkeydown="enterIn(this,event);" type="text" />
            <button type="submit" class="search-submit" onclick="search()">搜索</button>
        </div>
</form>

手机端

<script type="text/javascript">
    function search()
    {
        var q = document.getElementById("q").value;
        window.location.href = "http://m.abc.com/search/"+q+".html";
    }
    function enterIn(obj,evt)
    {
        var evt = evt ? evt : (window.event ? window.event : null);
        if (evt.keyCode == 13)
        {
            var q = obj.value;
            window.location.href = "http://m.abc.com/search/"+q+".html";
        }
    }
</script>

<form action="" method="post" onsubmit="return false">
    <div class="form">
        <h4>搜索</h4>
        <input name="q" id="q" onkeydown="enterIn(this,event);" type="text" />
        <button type="submit" class="search-submit" onclick="search()">搜索</button>
    </div>
</form>

五、织梦电脑版及手机版的伪静态规则

我们在设置全站伪静态后,访问管理目录(或者自己上传的其它静态目录)会要求在目录后面添加index.php(www.abc.com/dede/index.php)才能正常访问,如果直接访问(www.abc.com/dede/)刚会报错:Request Error!

所以,我们就得把不需要伪静态的目录排除。设置方法:找到下载的对应规则文件

nginx环境下的规则

#列表栏目
rewrite ^/(?!dede)(.*)/$ /plus/list.php?tid=$1;

(?!dede) 就是需要排除伪静态的目录。

apache环境下的规则

#列表栏目
RewriteRule ^(?!dede)(.*)/$ /plus/list.php?tid=$1

IIS7/IIS8 需要放在最前面

<rule name="织梦iis排除目录" stopProcessing="true"> <match ignoreCase="false" url="^(dede|m|admin)($|/)$"/> <action type="Rewrite" url="/{R:1}/index.php"/> </rule>

如果想过滤多个目录就在后面加一个竖线和目录名。比如(?!dede|admin),其它环境规则自己转换。

六、织梦手机站织梦伪静态规则-固定自由版m目录文件替换文件,解压后,替换根目录下的m文件夹即可。

七、电脑端模板添加跳转代码:

主页

<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>

列表页

<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>

内容页

<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>

测试看看伪静态现在正常了么。压缩包里面的手机模板都是默认的手机模板,如果出现样式问题或者是数据调用不出来。你可以按照下面的方法修改你的手机模板:

css、js、images 改成绝对路径,例如 assets/css/ 改成 /assets/css/
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('/[1-9][0-9]*/',$preurl,$match);
           $result = GetOneArchive($match[0]);
            @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('/[1-9][0-9]*/',$preurl,$match);
           $result = GetOneArchive($match[0]);                  
           @me = !empty($result) ? '下一篇:<a href="'.$result['arcurl'].'">'.$result['title'].'</a>' : "下一篇:没有了";
{/dede:prenext}

有个要注意的地方就是,dedecms手机站上一页下一页链接有错误,显示的都是上一页链接,修改方法:打开 \include\arc.archives.class.php 文件大约在839 行,查找 $mlink = 'view.php?aid='.$preRow['id']; 修改为 $mlink = 'view.php?aid='.$nextRow['id'];

文章内容 {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}

以上基本就完成了。但有一个问题。就是在网站根目录下仍会自动生成空的栏目文件夹。

解决方法:

第一步:打开\include\arc.listview.class.php 搜索

CreateDir(MfTypedir($this->Fields['typedir']));

总共有三处。全部替换为:

if($this->TypeLink->TypeInfos['isdefault']!=-1)
{
CreateDir(MfTypedir($this->Fields['typedir']));
}

第二步:打开\include\helpers\channelunit.helper.php 找到

CreateDir($okdir);

替换成:

if($ismake!=-1 || $cfg_rewrite == 'N')CreateDir($okdir);

第三步:打开后台管理目录\dede\catalog_add.php 搜索(dede对应自己的后台目录文件夹名)

if($ispart != 2)

替换成:

if($ispart != 2 && $isdefault != -1)
历史上的今天
08月
29
    抱歉,历史上的今天作者很懒,什么都没写!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。