本人比较懒,相信不少朋友也是,懒得每次去生成dedecms的HTML,同时为了现已不太有效的伪静态优化,所以还是搞搞伪静态吧。
本dedecms全站伪静态教程分为五部分,包括“Apache设置、.htaccess文件设置、首页伪静态、列表页伪静态、文章页伪静态”。
一、Apache文件设置
这是重头戏,以前用本地测试时因 httpd.conf 文件没设置好,搞得焦头烂额。
1、如果是虚拟主机,一般 apache 的 LoadModule rewrite_module modules/mod_rewrite.so 是开启的,请咨询你的主机提供商以确认是否支持伪静态。
2、如果是自己的服务器或本地机器,请按以下设置:
关闭 apache 服务。
打开 httpd.conf 文件(一般放在apache安装目录的conf目录下)把 #LoadModule rewrite_module modules/mod_rewrite.so 前的 # 号去掉,代表开启 rewrite 规则。
搜索 “AllowOverride None”(不包括引号,下同) ,有多个,全部替换为 “AllowOverride All”。
开启 apache 服务。
二、.htaccess文件设置
在网站根目录建一 .htaccess 文件,内容为:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)index\.html$ $1/index.php
RewriteRule ^(.*)list-([0-9]+)\.html$ $1/plus/list.php?tid=$2
RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3
RewriteRule ^(.*)view-([0-9]+).html$ $1/plus/view.php?aid=$2
RewriteRule ^(.*)view-([0-9]+)-([0-9]+).html$ $1/plus/view.php?aid=$2&pageno=$3
三、dedecms首页伪静态
不要更新首页html就行。如果已更新,请删除index.html即可。
四、dedecms列表页伪静态
1、打开 /include/inc_arclist_view.php 找到
//---------------------------------
//获取动态的分页列表
//---------------------------------
把它下面的函数改成以下的:
function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
{
$prepage="";
$nextpage="";
$prepagenum = $this->PageNo-1;
$nextpagenum = $this->PageNo+1;
if($list_len==""||ereg("[^0-9]",$list_len)) $list_len=3;
$totalpage = ceil($this->TotalResult/$this->PageSize);
if($totalpage<=1 && $this->TotalResult>0) return "共1页/".$this->TotalResult."条记录";
if($this->TotalResult == 0) return "共0页".$this->TotalResult."条记录";
$maininfo = "共{$totalpage}页/".$this->TotalResult."条记录";
$purl = $this->GetCurUrl();
$geturl = "typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$gettypeid =$this->TypeID."-";
//$hidenform = "<input type='hidden' name='typeid' value='".$this->TypeID."'>";
//$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>";
$purl .= "?".$geturl;
//获得上一页和下一页的链接
if($this->PageNo != 1){
$prepage.="<a href='list-".$gettypeid."$prepagenum.html'>上一页</a>";
$indexpage="<a href='list-".$gettypeid."1.html'>首页</a>";
}
else{
$indexpage="首页";
}
if($this->PageNo!=$totalpage && $totalpage>1){
$nextpage.="<a href='list-".$gettypeid."$nextpagenum.html'>下一页</a>";
$endpage="<a href='list-".$gettypeid."$totalpage.html'>末页</a>";
}