点击登录
  • 欢迎访问无限星辰技术博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏无限星辰吧
  • 好集导航开张了,传送门:好集导航

discuz门户栏目的伪静态开发,分页也实现伪静态 (目录化)

Discuz!问题集 crx349 9546次浏览 0个评论 扫描二维码

基于代码X3,其它版本源码,请自行验证。

Discuz后台的伪静态配置不包含门户频道页的伪静态配置。应该是考虑到频道页的URL地址变化太多的原因。下面,我们就来开发源码,加上这个功能。
第一步:加上语言包中的记录:
根目录下:source\language\lang_admincp.php ,找到setting_seo_rewritestatus_portal_article 这一行,大概在1500行左右,搜索一下吧。

在这句下面加上一句:

1
'setting_seo_rewritestatus_portal_list' => '门户频道页',

第二步:在后台加上设置项
根目录下:source\function\function_admincp.php ,找到rewritedata函数,在if语句的,两个大括号中,加上下面两段程序

上面一段加上

1
2
3
4
        if (in_array('portal_list', $_G['setting']['rewritestatus'])) {
            $data['search']['portal_list'] = "/" . $_G['domain']['pregxprw']['portal'] . "\?mod\=list&(amp;)?catid\=(\d+)(&page\=(\d+))?\"([^\>]*)\>/e";
            $data['replace']['portal_list'] = "rewriteoutput('portal_list', 0, '\\1', '\\3', '\\5', '\\6')";
        }

下面一段加上

1
2
3
4
        $data['rulesearch']['portal_list'] = 'list-{catid}-{page}.html';
        $data['rulereplace']['portal_list'] = 'portal.php?mod=list&catid={catid}&page={page}';
        $data['rulevars']['portal_list']['{catid}'] = '([0-9]+)';
        $data['rulevars']['portal_list']['{page}'] = '([0-9]+)';

第三步:兼容栏目页URL地址设置
找到文件:
根目录source\function\function_portal.php 下的函数getportalcategoryurl
重新写成下面的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function getportalcategoryurl($catid) {
    if (empty($catid))
        return '';
    loadcache('portalcategory');
    $portalcategory = getglobal('cache/portalcategory');
    if ($portalcategory[$catid]) {
        $url = str_replace('&', '&', $portalcategory[$catid]['caturl']);
        $url = str_replace('&', '&', $url);
        $url = str_replace('http://'.$_SERVER['HTTP_HOST'].'/', '', $url);
        return $url;
    } else {
        return '';
    }
}

第四步:设置前台页面URL地址切换
根目录\source\function\function_core.php 这个文件中找到:函数rewriteoutput
在一串的if … else if中加上一段

1
2
3
4
5
6
}elseif ($type == 'portal_list') {
        list(,,, $id, $page, $extra) = func_get_args();
        $r = array(
            '{catid}' => $id,
            '{page}' => $page ? $page : 1,
        );

第五步:设置output_replace函数真假检索分页链接,实现伪静态

根目录\source\function\function_core.php 这个文件中找到:函数output_replace,在其代码:
$content = preg_replace($_G[‘setting’][‘output’][‘preg’][‘search’], $_G[‘setting’][‘output’][‘preg’][‘replace’], $content);上方加入下面两行代码

1
2
       $_G['setting']['output']['preg']['search']['index']='/portal\.php\?mod\=list&catid\=([0-9]+)&(amp;)?page\=([0-9]+)/';
       $_G['setting']['output']['preg']['replace']['index']="list-$1-$3.html";

第五步:设置iis或Apache的伪静态规则
Discuz系统设置里面有伪静态的规则,自动生成的。全局-》SEO设置-》查看当前的 Rewrite 规则,找到规则就加载到iis或apache上面,这就大公告成了!


无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明discuz门户栏目的伪静态开发,分页也实现伪静态 (目录化)!
喜欢 (4)
[]
分享 (0)

您必须 登录 才能发表评论!