dedecms静态网站转换成伪静态,网址不变
1、登录网站后台,在“系统基本参数”中开启伪静态功能;在“SQL命令行工具”中使用以下语句修改栏目 和修改文章为动态访问。
修改栏目为动态:
UPDATE dede_arctype set isdefault='-1'
修改文章为动态:
UPDATE dede_archives set ismake='-1'
2、修改栏目伪静态:
打开文件include/helpers/channelunit.helper.php,找到函数GetTypeUrl,把函数中的这句代码:
$reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
修改为:
if($GLOBALS["cfg_rewrite"] == 'Y')
{
$reurl = $sitepath.'/';
}
else
{
$reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
}
3、修改栏目分页伪静态:
打开文件include/arc.listview.class.php,找到函数GetPageListDM,把函数中的这段代码:
if($cfg_rewrite == 'Y')
{
$nowurls = preg_replace("/\-/", ".php?", $purl);
$nowurls = explode("?", $nowurls);
$purl = $nowurls[0];
}
$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$purl .= '?'.$geturl;
修改为:
if($cfg_rewrite == 'Y')
{
$nowurls = preg_replace("/\_/", ".php?", $purl);
$nowurls = explode("?", $nowurls);
$purl = $nowurls[0];
}
$geturl = "tid=".$this->TypeID."&";
$purl .= '?'.$geturl;
另外再把这段代码:
if($cfg_rewrite == 'Y')
{
$plist = str_replace('.php?tid=', '-', $plist);
$plist = str_replace('&TotalResult=', '-', $plist);
$plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
}
修改为:
if($cfg_rewrite == 'Y')
{
$plist = str_replace('.php?tid=', '_', $plist);
$plist = str_replace('?tid=', 'list_', $plist);
$plist = str_replace('&TotalResult=', '_', $plist);
$plist = preg_replace("/&PageNo=(\d+)/i",'_\\1.html',$plist);
}
总共是修改两段代码,千万不要修改少了啊。
4、修改文章伪静态:
打开文件include/helpers/channelunit.helper.php,找到函数GetFileName,把函数中的这段代码:
if($cfg_rewrite == 'Y')
{
return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';
}
else
{
return $GLOBALS['cfg_phpurl']."/view.php?aid=$aid";
}
修改成:
if($cfg_rewrite == 'Y')
{
return $GLOBALS['cfg_basehost'].MfTypedir($typedir)."/".$aid.'.html';
}
else
{
return $GLOBALS['cfg_phpurl']."/view.php?aid=$aid";
}
5、添加伪静态规则:
新建文件.htaccess,在文件中添加如下伪静态规则,以栏目“精油的用法”为例子,其中id为1,文件保存目录为yongfa。
RewriteEngine on
RewriteRule ^/$ /index\.php
RewriteRule ^yongfa/$ /plus/list\.php\?tid=1
RewriteRule ^yongfa/list_1_([0-9]+)\.html$ /plus/list\.php\?tid=1&PageNo=$1
RewriteRule ^yongfa/([0-9]+)\.html$ /plus/view\.php\?aid=$1
有多少个栏目,就需要写多少次这个伪静态,栏目名和栏目tid不相同就可以了,tid必须要指定栏目的id号,其中
RewriteEngine on 和 RewriteRule ^/$ /index\.php 以及 RewriteRule ^yongfa/([0-9]+)\.html$ /plus/view\.php\?aid=$1
无需重复写。
本文为ouxiong123原创经验,谢绝转载。