欢迎来到素材无忧网,按 + 收藏我们
登录 注册 退出 找回密码

织梦电脑站和手机站伪静态+伪静态规则-自由目录版

时间: 2020-09-15 09:33 阅读: 作者:素材无忧网

请确保你网站所在的主机或者服务器支持伪静态并且已经开启了伪静态功能

本教程只适合给那些需要电脑版和手机版都想要伪静态的小伙伴使用!

开启成功后,登录后台时,必须在地址栏补加上index.php

Ps:后台登录不想加index.php或者某个文件夹想排除的小伙伴可以在栏目列表伪静态规则前面加个排除目录,添加后目录不使用伪静态

apache规则
#排除
RewriteRule ^(dede|m|admin)($|/)$ /$1/index.php [L]

nginx规则
rewrite ^/(dede|m|admin)($|/) /$1/index.php last;

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

网站后台开启伪静态选项

后台-系统参数-核心设置-是否使用伪静态:"是"

网站后台取消绝对路径

后台-核心设置-启用绝对网址 改成 【否】,不用担心手机站图片问题,下面手机站伪静态教程里有办法

网站后台设置整站为动态

电脑站伪静态教程开始

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

打开 /plus/list.php

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

//改成
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 arcrank>-1 and 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'])."/";

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);
}

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;
<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">
    <p class="form">
        <h4>搜索</h4>
        <input name="q" id="q" onkeydown="enterIn(this,event);" type="text" />
        <button type="submit" class="search-submit" onclick="search()">搜索</button>
    </p>
</form>

电脑站伪静态规则文件打包下载

链接: https://pan.baidu.com/s/1sj8H36GdeqZtd0cqislr3w 提取码: e2rh

包括iis6、iis7、8、apache、nginx,下载后选择对应的伪静态规则文件

手机版伪静态教程开始

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

2.后台-系统配置 添加变量

(为了使用绝对路径,使用电脑版的文章图片,为了移动版模板css、js、images使用绝对路径)

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

3.移动版当前位置 {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'];
}

4.m文件夹文件添加和替换

手机站m文件夹目录里添加了[搜索文件search.php]和[标签文件tags.php],还修改了以下3个文件

index.php list.php view.php

我已经修改好并打包,如果你有改过,请备份你的再覆盖我的,下载地址:

链接: https://pan.baidu.com/s/11T18yEe0D7bdAiLRYI6ojg 提取码: cmhm 

5.手机站伪静态规则文件打包下载

链接: https://pan.baidu.com/s/1FH5BSdfSmKrNbvNAUblFzg 提取码: fzvz 

包括iis6、iis7、8、apache、nginx,下载后选择对应的伪静态规则文件

6.把所有手机版模板文件(_m.htm 结尾的),把模板里面的代码都改成电脑版

还有几个特别的,请认真对比下面

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/]">

上下篇记得先修正官方程序的这个BUG,已经修正过的跳过

http://www.freshtime.cn/development/06063A2019.html

上一篇标签 {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}

文章内容 {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/', $cfg_basehost.'/uploads/', $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/', $cfg_basehost.'/uploads/', $content);
{/dede:field.content}

搜索框代码改成静态的js提交搜索,参考下面代码,注意标红的地方

<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">
    <p class="form">
        <h4>搜索</h4>
        <input name="q" id="q" onkeydown="enterIn(this,event);" type="text" />
        <button type="submit" class="search-submit" onclick="search()">搜索</button>
    </p>
</form>

电脑站跳转到手机站代码

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>

 

版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

转载请注明: 织梦电脑站和手机站伪静态+伪静态规则-自由目录版

模板推荐