首页 > CMS建站 > PhpCMS > 正文

PHPCMS V9自定义栏目的伪静态规则

2020-10-10 21:28:21
字体:
来源:转载
供稿:网友

PHPCMS V9自定义栏目伪静态规则教程(支持自定义目录名),官方程序默认伪静态是不支持自定义栏目名的,我们做以下修改使其支持自定义目录.

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

  1. 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']);替换成:

  1. 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];} 

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

  1. 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,找到如下代码:

  1. if (!$setting['ishtml']) { //如果不生成静态   将下面的: 
  2.  
  3. $url=str_replace(array('{$catid}','{$page}'),array($catid,$page),$urlrule);if(strpos($urls,'//')!==false){$url=APP_PATH.str_replace('//','/',$urls);} 
  4. //Cuoxin.com 
  5. //替换成: 
  6.  
  7. $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." 
  8. "; if(strpos($urls,'//')!==false){$urls=APP_PATH.str_replace('//','/',$urls);}$url=$domain_dir.$urls

3、后台URL规则中添加:url示例:1/url规则:

{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/

最后更新栏目缓存.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表