首页 > 运营 > 帮助中心 > 正文

phpcmsV9栏目伪静态的修改方法(支持自定义目录名)

2019-10-17 22:30:48
字体:
来源:转载
供稿:网友

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

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

XML/HTML代码
  1. RewriteRule /phpcms/(.*)(.*)/ /phpcms/index/.php/?m=contentc=indexa=listscategorydir=$1catdir=$2   
  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']);替换成:

PHP代码
  1. if(isset ($_GET['catid'])){   
  2.                     $catid = intval($_GET['catid']);   
  3.                 }else{   
  4.                     $catdir=$_GET['catdir'];   
  5.                     if($catdir==""){   
  6.                         $catdir=$_GET['categorydir'];   
  7.                     }   
  8.                     $s=$this->_getCategoryId($catdir);   
  9.                     $catid=$s[0][catid];                      
  10.                 }  

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

PHP代码
  1. /** 
  2.          *根据栏目名获得ID 
  3.          * @param <type> $catdir 
  4.          */  
  5.         function _getCategoryId($catdir){   
  6.             $this->category_db = pc_base::load_model('category_model');   
  7.             $result = $this->category_db->select(array('catdir'=>$catdir));   
  8.            // print_r($result);   
  9.             return $result;   
  10.          }  

2、打开phpcms/modules/content/classes目录中的url.class.php,找到 
if (!$setting['ishtml']) { //如果不生成静态
将下面的:
 

PHP代码
  1. $url = str_replace(array('{$catid}''{$page}'), array($catid$page), $urlrule);   
  2.             if (strpos($urls'//')!==false) {
  3.                     $url = APP_PATH.str_replace('//', '/', $urls);   
  4.             }  

替换成:

PHP代码
  1. $domain_dir = '';   
  2.             if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {   
  3.                 if (preg_match('/^((http|https):////)?([^//]+)/i'$category['url'], $matches)) {   
  4.                     $match_url = $matches[0];   
  5.                     $url = $match_url.'/';   
  6.                 }   
  7.                 $db = pc_base::load_model('category_model');   
  8.                 $r = $db->get_one(array('url'=>$url), '`catid`');   
  9.   
  10.                 if($r$domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';   
  11.             }   
  12.             $categorydir = $this->get_categorydir($catid);   
  13.             $catdir = $category['catdir'];   
  14.             $year = date('Y',$time);   
  15.             $month = date('m',$time);   
  16.             $day = date('d',$time);   
  17.             //echo $catdir;   
  18.             $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}'  
  19. ,'{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule);   
  20.                        // echo $urls."<br>";   
  21.                         if (strpos($urls'//')!==false) {
  22.                     $urls = APP_PATH.str_replace('//', '/', $urls);   
  23.             }   
  24.                         $url = $domain_dir.$urls;  

3、后台URL规则中添加:

XML/HTML代码
  1. url示例:1/   
  2. url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/  

更新栏目缓存就OK了。

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