PHPCMS伪静态的设置方法

第一步:验证服务器或虚拟主机是否支持伪静态:

①虚拟主机:询问主机提供商,看是否只是伪静态;

②本地服务器:

Apache 配置文件 httpd.conf

1、LoadModule rewrite_module modules/mod_rewrite.so 
把这句的“#”注释掉。
2、AllowOverride none 改为 AllowOverride all
重启apache服务器。



..................................................................................................................

一般虚拟空间 只做下面这步

第二步:详细设置:

①在根目录上上传名为 .htaccess 的文件,如果里面请在里面增加相应代码; 代码如下:
RewriteEngine On
RewriteRule ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=$3&page=$4
RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=$3&page=$4
RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3


第三步:进入PHPCMS后台设置:

①位置:内容-->管理栏目-->生成HTML项目

栏目页URL规则:list-1-2-1.html
内容页URL规则:content-1-2-1.html

第四步:批量更新URL:

①位置:内容-->批量更新URL

②更新缓存

恭喜你:完成伪静态设置!按上述步骤就能完成设置!

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。


PHPCMS V9自定义栏目伪静态实现方法

phpcmsV9栏目伪静态的修改方法(支持自定义目录名),官方程序默认伪静态是不支持自定义栏目名的,所以今天就做了以下修改,让其支持!

首先看urlrewrite的规则,这个是IIS6下的,其它环境下的规则自己转换下

RewriteRule /phpcms/(.*)(.*)/ /phpcms/index\.php\?m=contentc=indexa=listscategorydir=$1catdir=$2   
RewriteRule /phpcms/(.*)(.*)/([0-9]+)/ /phpcms/index\.php\?m=contentc=indexa=listscategorydir=$1catdir=$2page=$3  

1、打开phpcms\modules\content目录下的index.php找到 public function lists() {,将$catid = intval($_GET['catid']);替换成:

if(isset ($_GET['catid'])){ $catid = intval($_GET['catid']); }else{ $catdir=$_GET['catdir']; if($catdir==""){ $catdir=$_GET['categorydir']; } $s=$this->_getCategoryId($catdir); $catid=$s[0][catid]; } 

并且在最后的}?> 前添加:

/**   *根据栏目名获得ID   * @param <type> $catdir   */ function _getCategoryId($catdir){ $this->category_db = pc_base::load_model('category_model'); $result = $this->category_db->select(array('catdir'=>$catdir)); // print_r($result);  return $result; } 

2、打开phpcms\modules\content\classes目录中的url.class.php,找到

if (!$setting['ishtml']) { //如果不生成静态

将下面的:

$url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule); if (strpos($urls, '\\')!==false) { $url = APP_PATH.str_replace('\\', '/', $urls); } 

替换成:

$domain_dir = ''; if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) { if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) { $match_url = $matches[0]; $url = $match_url.'/'; } $db = pc_base::load_model('category_model'); $r = $db->get_one(array('url'=>$url), '`catid`'); if($r) $domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/'; } $categorydir = $this->get_categorydir($catid); $catdir = $category['catdir']; $year = date('Y',$time); $month = date('m',$time); $day = date('d',$time); //echo $catdir;  $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}','{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule); // echo $urls."<br>";  if (strpos($urls, '\\')!==false) { $urls = APP_PATH.str_replace('\\', '/', $urls); } $url = $domain_dir.$urls;

3、后台URL规则中添加:

url示例:1/ url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/ 



本文由瞎悟学习网作者:hiovo 发表,其版权均为本站所有,文章内容系作者个人观点瞎悟学习,不代表对观点赞同或支持。如需转载,请注明文章来源。

    匿名评论
  • 评论
人参与,条评论