您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程

phpcmsv9栏目伪静态自定义为栏目英文目录名的方法

颜东鑫2025-05-29phpcms教程已有人查阅

导读1,后台增加url规则,增加后.导航上,或分页号上,会自动替换为静态的样式.类似 .abc.com/news/2/ 2表示页码phpcms v9 的后台扩展,url规则,添加两个规则,

1,后台增加url规则,增加后.导航上,或分页号上,会自动替换为静态的样式.类似 .abc.com/news/2/ 2表示页码
phpcms v9 的后台扩展,url规则,添加两个规则,
一个是名称为category的规则,规则的前面的斜线可以去掉,不过可能影响分页问题
/{$catdir}/|/{$catdir}/{$page}/
url示例为.abc.com/news/
一个是名称为show规则
{$catdir}/{$id}.html|{$catdir}/{$id}_{$page}.html
示例为 .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
#上面栏目分页,是完全的字母加数字的形式,如 .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,文件,phpcms\phpcms\modules\content\index.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));
// print_r($result);
return $result;
}
4, 打开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('\\', '/', $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;

本文标签:

很赞哦! ()

相关源码

  • (自适应)大型农业机械设备水稻玉米收割机网站pbootcms源码下载本模板基于PbootCMS内核开发,为农业机械设备制造与销售企业设计,特别适合水稻玉米收割机、拖拉机、播种机等农用机械展示。模板充分考虑了农机行业的特性,从产品展示到技术参数,从作业案例到售后服务查看源码
  • (自适应响应式)刷卡机POS机无线支付设备pbootcms网站源码下载本模板基于PbootCMS系统开发,为支付终端设备企业设计,特别适合POS机、移动支付终端、刷卡设备等金融科技产品展示。采用响应式布局技术,确保各类支付终端产品在不同设备查看源码
  • (响应式)蓝色智能摄像头安防防盗电子设备免费pbootcms源码下载这是一款针对智能安防行业特点设计的网站模板,采用蓝色系配色方案,体现科技感和安全性。模板包含产品展示、解决方案、技术支持和新闻中心等核心模块,能够全面展示智能安防设备的技术特点和行业应用。查看源码
  • (自适应响应式)宠物经验资讯咨询博客pbootcms网站源码下载除宠物资讯领域外,通过内容替换可快速适配宠物用品商城、宠物医疗咨询平台、宠物训练教程网站、动物保护组织官网、水族爱好者社区等垂直领域。查看源码
  • (PC+WAP)绿色硅胶橡胶玩具制品营销型网站源码下载为硅胶橡胶制品及玩具行业打造的营销型网站模板,采用PbootCMS内核开发,通过模块化设计实现产品参数、安全认证、应用场景等专业内容的可视化呈现,助力企业建立可信赖的线上展示平台。查看源码
  • 自适应黑色建筑装饰设计公司个人工作室pbootcms模板基于PbootCMS内核开发的黑金风格模板,为建筑装饰、工程设计类企业打造,采用‌开源架构‌,支持跨行业快速适配,核心优势如下: 查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐