phpcms v9 目录式伪静态

来源:互联网 发布:知乎匿名回答在哪看 编辑:程序博客网 时间:2024/05/20 05:09

phpcms v9 目录式伪静态

官方程序默认伪静态是不支持自定义栏目名的


如何才能实现目录式伪静态?

  1. pc 能够通过目录访问到正确页面

    • 默认可访问链接==>

      index.php?m=content&c=index&a=lists&catid=1

      index.php?m=content&c=index&a=show&catid=1&id=18

    • 需要可访问链接 ==>

      index.php?m=content&c=index&a=lists&catdir=dir1

      index.php?m=content&c=index&a=show&catdir=dir1&id=18

  2. pc后台 URL规则管理 需要正确配置

    ps: pc默认情况下 URL规则中 {$categorydir} {$catdir} 无效,也需要解决

  3. .htaccess 文件配置好对应伪静态


栏目伪静态时 URL规则中 {$categorydir} {$catdir} 无效解决方法

栏目页伪静态(不生成HTML)时,URL规则中 {$categorydir} {$catdir} 仍显示为 {$categorydir} {$catdir} 解决方法。

  1. 打开 phpcms\modules\content\classes\url.class.php 定位到 122

    $url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule);
  2. 替换成

    $category_dir = $this->get_categorydir($catid);$url = str_replace(array('{$catid}', '{$page}','{$catdir}','{$categorydir}'), array($catid, $page,$category['catdir'],$category_dir), $urlrule);

PS: 只做到这一步,生成的URL还是会有BUG的(分页url里有重复的栏目路径),继续往下,全部写完就没问题了!


让pc能通过目录式链接访问网站

phpcms v9 默认是无法通过栏目名访问到正确页面的,因为缺少必要的参数。

list页面 支持目录式访问网站

  1. 打开phpcms\modules\content\index.php 定位到 207

    $catid = $_GET['catid'] = intval($_GET['catid']);
  2. 替换成

    if(isset ($_GET['catid'])){    $catid = $_GET['catid'] = intval($_GET['catid']);} else{    $catid=$this->_getCategoryId($_GET['catdir']);}
  3. 在该文件底部( }?> 前)增加一个方法

    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'];}

show页面 支持目录式访问网站

  1. 打开phpcms\modules\content\index.php 定位到 35-36

    $catid = intval($_GET['catid']);$id = intval($_GET['id']);
  2. 替换成

    if(isset ($_GET['catid'])){    $catid = intval($_GET['catid']);} else{    $catid=$this->_getCategoryId($_GET['catdir']);}if(isset($_GET['id'])){    $id = intval($_GET['id']);} else{    $id = $this->_getPrefixId($_GET['catdir'],$_GET['prefix']);}
  3. 在该文件底部( }?> 前)增加一个方法

    private function _getPrefixId($catdir,$prefix){    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));    $catid = $result['catid']; $siteids = getcache('category_content','commons');    $siteid = $siteids[$catid]; $CATEGORYS = getcache('category_content_'.$siteid,'commons');    if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank');    $this->category = $CAT = $CATEGORYS[$catid];    $this->category_setting = $CAT['setting'] = string2array($this->category['setting']);    $siteid = $GLOBALS['siteid'] = $CAT['siteid'];    $MODEL = getcache('model','commons');    $modelid = $CAT['modelid'];    $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];    $result = $this->db->get_one(array('prefix'=>$prefix));    if(empty($result)){ $result = $this->db->get_one(array('id'=>$prefix)); } return $result['id'];}

URL规则管理 与 伪静态规则

伪静态规则 需要根据 URL规则 进行自定义

自带伪静态规则

    RewriteEngine on    RewriteRule ^content-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3    RewriteRule ^show-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3    RewriteRule ^list-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=lists&catid=$1&page=$2

第1组 URL规则 or 伪静态规则

  1. categoryURL示例 or URL规则

    dir/index.html|dir/list-1.html{$catdir}/index.html|{$catdir}/list-{$page}.html
  2. showURL示例 or URL规则

    dir/1.html|dir/1-1.html{$catdir}/{$id}.html|{$catdir}/{$id}-{$page}.html
  3. 伪静态规则

    RewriteEngine onRewriteRule ^index.html index.phpRewriteCond $1 !^(api|caches|html|kc-path|phpcms|phpsso_server|statics|uploadfile)RewriteRule ^(\w+)/(list\-(\d+)\.html)? index.php?m=content&c=index&a=lists&catdir=$1&page=$3RewriteRule ^(\w+)/(\d+)(\-(\d+))?\.html index.php?m=content&c=index&a=show&catdir=$1&id=$2&page=$4

第2组 URL规则 or 伪静态规则

  1. categoryURL示例 or URL规则

    dir.html|dir-1.html{$catdir}.html|{$catdir}-{$page}.html
  2. showURL示例 or URL规则

    dir/1.html|dir/1-1.html{$catdir}/{$id}.html|{$catdir}/{$id}-{$page}.html
  3. 伪静态规则

    RewriteEngine onRewriteRule ^index.html index.phpErrorDocument 404 /Error.htmlRewriteCond $1 !^(api|caches|html|kc-path|phpcms|phpsso_server|statics|uploadfile)RewriteRule ^(\w+)/(\d+)(\-(\d+))?\.html index.php?m=content&c=index&a=show&catdir=$1&id=$2&page=$4RewriteCond $1 !^(Error|js|index)RewriteRule ^((\w+)(\-(\d+))?)\.html index.php?m=content&c=index&a=lists&catdir=$2&page=$4

原创粉丝点击