异度传媒 异度传媒
  • 首页
  • 异度传媒官网
  • 互联网
    • 敲代码
    • 搞软件
    • 玩游戏
  • 联系我们
  • 注册 登录
立即登录
  • 首页
  • 异度传媒官网
  • 互联网
    • 敲代码
    • 搞软件
    • 玩游戏
  • 联系我们
  • 拨打电话
首页 › 敲代码 › phpcms自定义栏目伪静态实现方法
phpcms 伪静态

phpcms自定义栏目伪静态实现方法

2019年12月29日
0 0

phpCMS V9栏目伪静态的修改方法(支持自定义目录名),官方程序默认伪静态是不支持自定义栏目名的,所以今天就做了以下修改,让其支持!

首先看 urlrewrite 的规则,这个是 Apache 下的规则:

#栏目页
#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
#内容页
RewriteRule ^([0-9A-Za-z_-]*)/([0-9]+)\.html$ index.php?m=content&c=index&a=show&catdir=$1&id=$2

这个是 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.修改 index.php 文件

文件目录 phpcms\modules\content

找到“public function lists() {”,将以下代码:

$catid = $_GET['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];
}

找到“public function show() {”,将以下代码:

$catid = intval($_GET['catid']);

替换成:

if(isset ($_GET['catid'])){
	$catid = intval($_GET['catid']);
}else{
	$catdir=$_GET['catdir'];
	$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.修改 url.class.php 文件

文件目录 phpcms\modules\content\classes

找到“if (!$setting['ishtml']) {”,将以下代码:

$url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule);
if (strpos($url, '\\')!==false) {
	$url = APP_PATH.str_replace('\\', '/', $url);
}

替换成:

$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;

3.后台URL规则中添加

url示例:newscenter/news/
url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/

url示例:news/
url规则:{$catdir}/|{$catdir}/{$page}/

4.其他

a.更新栏目缓存

b.批量更新URL

0 0

微信扫一扫支持一下我们

等0人赞过
相关文章
phpcms栏目内文章数量统计调用
phpcms调用指定栏目名称、url、图片、描述、子栏目、文章
phpcms判断首页列表页内页分类
phpcms实现PC端与手机端双模版的方法
phpcms搬家只更换域名需要修改的配置
评论 (88)
请登录以参与评论。
立即登录
  • 游客

    评论系统正在维护中……

    2019年12月29日
    回复
    • 游客评论

      @游客 评论系统正在维护中……

      2019年12月29日
      回复
异度小编管理员
推荐阅读
phpcms访问单网页一级栏目自动跳转到其下的第一个子栏目
2020-02-23
phpcms去掉CKEditor编辑器上传图片的宽高样式
2020-03-12
彻底解决phpcms V9二级域名下分页路径不正确问题
2020-07-15
phpcms后台添加内容如何才不弹出新的浏览器窗口
2019-12-29
点击自定义超链接按钮弹出百度商桥对话框
2019-12-29
最新文章
JavaScript根据不通的域名显示不同的备案号和内容
2020年08月16日
经常一个网站会绑定多个域名,根据不同域名显示不同的备案号。以下用 JavaScript 来实现这个效果。JavaScript根据不通的域名显示不同的备案号和内容
[阅读全文]
彻底解决phpcms V9二级域名下分页路径不正确问题
2020年07月15日
在用 phpcms V9 做二次开发的时候,做英文站的时候经常会在根目录新建子目录来搭建一个新站,我使用的是伪静态,分页的时候分页地址出现错误,分页地址显示的是根域名的地址。
[阅读全文]
网站不支持timthumb.php的解决方法
2020年07月03日
由于timthumb php基于安全问题,所以它不支持指定网站的外部链图像以外的任何外部链映像;另一方面,它是由于处理本机图片地址造成的。
[阅读全文]
轻量级图片懒加载 echo.js
2020年06月05日
echo是一个独立的JavaScript(不依靠jQuery)、轻量级的、延迟图片加载插件,echo压缩后体积不到1k,使用html的标准data-*属性,echo支持IE8+。
[阅读全文]
phpcms调用栏目及循环调用多个子栏目中的文章列表
2020年03月31日
phpcms调用栏目及循环调用多个子栏目中的文章列表,特别适用于有3级目录,在2级目录调用所有3级子目录的所有文章。
[阅读全文]
更多
标签
淘宝 优惠券 红色警戒 正则表达式 伪静态 timthumb emlog EditPlus phpcms SSL 阿里云 编程 游戏 destoon 缩略图 批处理 css html 百度商桥 javascript
更多
  • 首页
  • 关于我们
  • 文章列表
  • 联系我们
Copyright © 异度传媒 2009-2021 粤ICP备16051972号-3 Sitemap
友情链接: 领潮照明