phpcms url.class.php,PHPCMS V9栏目伪静态url自定义的实现方法(支持自定义目录名)...

c58265e72272c8461c5092b8cc4f6095.gif

帝国CMS技术互助群:540946827 一帮大神带你装逼带你飞!还有漂亮的妹纸陪你玩哦!

a0f609b288c7de88131b6f6ba37c81b3.png

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 $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('\\', '/', $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;

3、后台URL规则中添加:

url示例:1/

url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/

保存后更新栏目缓存就可以。

如对本文有疑问,请提交到交流社区,广大热心网友会为你解答!! 点击进入社区

打赏一下,我们会为大家提供更多优质资源!

91e7dcaaa1a0bd41a6bdf0bdc709f045.png

您的打赏将全部用来搜集更多优质资源!

weipayimg.jpg

扫码打赏,你说多少就多少

cc16f7477eabc8420c6a2b3eb63a44b8.png

cbb949506e1f1b1153ebda7bc4c213c4.png

打开微信扫一扫,即可进行扫码打赏哦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值