- private function _getCategoryId($catdir){
- if(!strpos($catdir,'/')) {
- $dirname = $catdir;
- }else {
- $dirname = end(explode('/',$catdir));
- }
- $this->category_db = pc_base::load_model('category_model');
- $result = $this->category_db->get_one(array('catdir'=>$dirname));
- return $result['catid'];
- }
增加一个方法,用于将`catdir`转换为`catid`
然后在`show()`方法中,将获取`catid`的语句修改,大概35行找到:
改成:
- $catid = intval($_GET['catid']
然后在在lists()方法中找到207行,将获取’catid’的语句修改
- if(isset ($_GET['catid'])){
- $catid = intval($_GET['catid']);
- }else{
- $catid=$this->_getCategoryId($_GET['dir']);
- }
改成:
- $catid = $_GET[‘catid’] = intval($_GET[‘catid’]);
然后找到大概260行:
- if(isset ($_GET['catid'])){
- $catid = intval($_GET['catid']);
- }else{
- $catid=$this->_getCategoryId($_GET['dir']);
- }
改成:
- $GLOBALS['URL_ARRAY']['categorydir'] = $categorydir;
- $GLOBALS['URL_ARRAY']['catdir'] = $catdir;
- $GLOBALS['URL_ARRAY']['catid'] = $catid;
- $GLOBALS['URL_ARRAY']['categorydir'] = $parentdir;
- $GLOBALS['URL_ARRAY']['catdir'] = $catdir;
- $GLOBALS['URL_ARRAY']['catid'] = $catid;
2、打开phpcmsmodulescontentclasses目录中的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、分页问题处理 phpcmslibsfunctionsglobal.func.php
- /**
- * 返回分页路径
- *
- * @param $urlrule 分页规则
- * @param $page 当前页
- * @param $array 需要传递的数组,用于增加额外的方法
- * @return 完整的URL路径
- */
- function pageurl($urlrule, $page, $array = array()) {
- if(strpos($urlrule, '~')) {
- $urlrules = explode('~', $urlrule);
- $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
- }
- $findme = array('{$page}');
- $replaceme = array($page);
- if (is_array($array)) foreach ($array as $k=>$v) {
- $findme[] = '{$'.$k.'}';
- $replaceme[] = $v;
- }
- $url = str_replace($findme, $replaceme, $urlrule);
- $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
- if (!strstr($url,siteurl(get_siteid()))){
- $url = siteurl(get_siteid()) . '/' . $url;
- }
- return $url;
- }
(4)后台增加伪静态url规则
(5)增加伪静态规则
- URL规则栏目页:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/index_{$page}.html
- URL规则内容页: {$categorydir}{$catdir}/{$id}.html|{$categorydir}{$catdir}/{$id}_{$page}.html
.htaccess为例:
- RewriteEngine on
- #静态文件以及API目录不需要伪静态
- RewriteRule ^(statics|api|uploadfile)(.*) – [L]
- #内容页
- RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+).html index.php?m=content&c=index&a=show&dir=$1&id=$2
- RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+)_([0-9]+).html index.php?m=content&c=index&a=show&dir=$1&id=$2&page=$3
- #栏目页
- RewriteRule ^([0-9A-Za-z_/]*)/index_([1-9][0-9]*).html index.php?m=content&c=index&a=lists&dir=$1&page=$2
- RewriteRule ^([0-9A-Za-z_/]*)/ index.php?m=content&c=index&a=lists&dir=$1