网站首页学无止境PHP
PHPCMS V9自定义栏目伪静态实现方法
发布时间:2014-07-23 16:35:17编辑:songlin阅读(273)
- 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
- $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
$catdir - */
- function _getCategoryId($catdirs){
- $this->category_db = pc_base::load_model('category_model');
- $catdirarr=explode('/',trim($catdirs,'/'));
- $catdir=array_pop($catdirarr);
- $parentdir= array_pop($catdirarr);
- $parentdir = $parentdir!=null ? $parentdir.'/': '';
- $result = $this->category_db->get_one(array('parentdir'=>$parentdir,'catdir'=>$catdir));
- return $result;
- }
- $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."";
- if (strpos($urls, '\\')!==false) {
- $urls = APP_PATH.str_replace('\\', '/', $urls);
- }
- $url = $domain_dir.$urls;
- url示例:1/
- url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/
最近用phpcms V9做个站,需要做栏目伪静态,上网查了好久发现都是几年以前发布的,由于phpcms更新的比较频繁,有好多规则都已经改变了。没办法只能自己在写一下,当然也有copy别人的东西(有现成的为毛不用)。本文的方法是用于最新发布的几个phpcms v9版本。本文的修改方法支持自定义目录名,例如www.xxx.com/news/。官方程序默认伪静态是不支持自定义栏目名的,所以今天就做了以下修改,让其支持!
首先看urlrewrite的规则,这个是linux下Apache的.htaccess 文件部分代码,其它环境下的规则如有需要自己转换
1、打开phpcms\modules\content目录下的index.php找到 public function lists() {,将
替换成:
替换成:
并且在最后的
前添加:
前添加:
2、打开phpcms\modules\content\classes目录中的url.class.php,找到
if (!$setting['ishtml']) { //如果不生成静态
将下面的:
替换成:
3、后台URL规则中添加:
更新栏目缓存就OK了。