phpcms v9 栏目伪静态完全自定义为栏目英文目录名
- 1,后台增加url规则,增加后.导航上,或分页号上,会自动替换为静态的样式.类似www.abc.com/news/2/ 2表示页码
- phpcms v9 的后台扩展,url规则,添加两个规则,
-
- 一个是名称为category的规则,规则的前面的斜线可以去掉,不过可能影响分页问题
- /{$catdir}/|/{$catdir}/{$page}/
- url示例为 www.abc.com/news/
- 一个是名称为show规则
- {$catdir}/{$id}.html|{$catdir}/{$id}_{$page}.html
- 示例为www.abc.com/news/99.html
-
-
-
- 然后,找到想伪静态的栏目,修改.生成html设置,生成Html全设置为否,url规则选择自己刚才设置的.保存,
-
- 最后更新栏目缓存及批量更新url,不更新无效
-
- 2,如果为apache的服务器空间,伪静态规则如下,注意,要保存在.htaccess 文件中,并上传到网站根目录中,其它规则自己转换
-
-
- RewriteEngine on
- #静态文件以及API目录不需要伪静态
- RewriteRule ^(statics|api|uploadfile)(.*) - [L]
- #栏目页
- RewriteRule ^([0-9A-Za-z_]*)$ index.php?m=content&c=index&a=lists&catdir=$1
- RewriteRule ^([0-9A-Za-z_]*)/$ index.php?m=content&c=index&a=lists&catdir=$1
- RewriteRule ^([0-9A-Za-z_]*)/([0-9]+)$ index.php?m=content&c=index&a=lists&catdir=$1&page=$2
- RewriteRule ^([0-9A-Za-z_]*)/([0-9]+)/$ index.php?m=content&c=index&a=lists&catdir=$1&page=$2
- #上面栏目分页,是完全的字母加数字的形式,如www.abc.com/news/2 ,后面不带其它字符,或加一个/字符,如果服务器伪静态匹配到了"域名/字母/数字/"的组合,则会自动跳转到index.php?m=content&c=index&a=lists&catdir=$1&page=$2这个页面中.所以.前面的规则不可重复,否则会错乱.
-
- #内容页
- RewriteRule ^([0-9A-Za-z_]*)/([0-9]+).html$ index.php?m=content&c=index&a=show&catdir=$1&id=$2
-
-
- 3,文件,phpcmsphpcmsmodulescontentindex.php中
- 搜索
- $catid = intval($_GET['catid']);
- 一共两处,修改为
-
- if(isset ($_GET['catid'])){
- $catid = intval($_GET['catid']);
- }else{
- $catdir=$_GET['catdir'];
- $s=$this->_getCategoryId($catdir);
- $catid=$s[0][catid];
- }
-
-
- 然后,在最下面
- } 这个 大括号的前面增加一个函数,如下
-
-
- protected function _getCategoryId($catdir){
- $this->category_db = pc_base::load_model('category_model');
- $result = $this->category_db->select(array('catdir'=>$catdir));
-
- return $result;
- }
-
-
-
-
- 4, 打开phpcmsmodulescontentclassesurl.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);
-
- $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}','{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule);
-
- if (strpos($urls, '\')!==false) {
- $urls = APP_PATH.str_replace('\', '/', $urls);
- }
- $url = $domain_dir.$urls;
-
-
-
原文地址:https://www.cnblogs.com/keta/p/8426936.html