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('\\', 'http://down.chinaz.com/', $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.'http://down.chinaz.com/';
}
$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'].'http://down.chinaz.com/';
}
$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('\\', 'http://down.chinaz.com/', $urls);
}
$url = $domain_dir.$urls;

  3、靠山URL法则中添加:

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

  更新栏目缓存就OK了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10147.html