找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 503|回复: 1

Discuz! X3.4主题分类和分类信息伪静态设置方法

[复制链接]
d
0 0
  @ME: 
发表于 2021-10-23 15:46:01 | 显示全部楼层 |阅读模式
  • 吉安交友查询:性别: 年龄: ~ 高级查找
  • 马上注册,结交更多吉安好友,享用更多功能,让你轻松玩转吉安论坛。

    您需要 登录 才可以下载或查看,没有账号?马上注册

    ×
    本帖最后由 完美主义 于 2021-10-23 15:52 编辑

    网上99%都是不完善和残缺的 或者各种不兼容,有的论坛还复制别人的DZ3.2版本的伪静态方法说是支持3.4版本的,全是让人浪费时间。

    A、主题分类伪静态设置方法:

    准备好修改的模板文件:forumdisplay.htm和forumdisplay_list.htm

    这两个文件都在 \template\default\forum 的目录下(有修改过discuz模板,以你的主题文件路径为准,如/template/主题模板文件夹/forum)。

    我们要先修改主题分类的:打开forumdisplay.htm的源代码:

    默认主题一般在415行,当然如你的主题有修改过discuz模板,以你的主题文件路径为准

    1.修改forumdisplay.htm文件中
      1. <li><a href="forum.php?mod=forumdisplay&fid=$_G[fid]&filter=typeid&typeid=$id$forumdisplayadd[typeid]{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}">
      复制代码



    修改为:

      1. <li><a href="forumtype-$_G[fid]-$id-$page.html{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}">
      复制代码



    2.接下来再打开forumdisplay_list.htm的源代码:默认主题一般在162行,如你的主题有修改过模板,以你的主题文件为准找到:

      1. <a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst">$thread[subject]</a>
      复制代码



    修改为:

      1. <a href="forum.php?mod=viewthread&tid=$thread[tid]{if $_G['gp_archiveid']}&archiveid={$_G['gp_archiveid']}{/if}"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst">$thread[subject]</a>
      复制代码



    3.主题类别前缀【只显示文字】,2个地方需要修改

    i、打开source\module\forum\forum_forumdisplay.php,查找
    1. forum.php?mod=forumdisplay&fid='.$_G['fid'].'&filter=typeid&typeid='.$thread['typeid'].'
    复制代码



    替换为:
    1. forumtype-'.$_G['fid'].'-'.$thread['typeid'].'-1.html
    复制代码


    ii、打开模板目录viewthread.htm,查找
    1. forum.php?mod=forumdisplay&fid=$_G[fid]&filter=typeid&typeid=$_G[forum_thread][typeid]
    复制代码


    替换为:

    1. forumtype-$_G[fid]-{$_G[forum_thread][typeid]}-1.html
    复制代码


    最后我们要把主题分类的伪静态规则添加到相应文件中,规则如下

    (因为环境问题,只测试了.htaccess,其它请自行测试):

    .htaccess 伪静态规则 请在RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1下面增加:

      1. RewriteCond %{QUERY_STRING} ^(.*)$
      2. RewriteRule ^forumtype-(\w+)-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&filter=typeid&typeid=$2&page=$3&%1
      复制代码



    注意:增加的规则不能放最后,特别是不能 不能 不能放在插件规则RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1 2&%1之后,不然访问分类伪静态会出现“插件不存在或删除”的错误。

    httpd.ini 伪静态规则
    1. RewriteRule ^(.*)/forumtype-(\w+)-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&filter=typeid&typeid=$3&page=$4&$5
    复制代码



    web.config 伪静态规则

      1. <rule name="forum_forumtype">
      2. <match url="^(.*/)*forumtype-(\w+)-(\w+)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
      3. <action type="Rewrite" url="{R:1}/forum.php\?mod=forumdisplay&fid={R:2}&filter=typeid&typeid={R:3}&page={R:4}&{R:5}" />
      4. </rule>
      复制代码



    B、分类信息列表内的帖子设置伪静态方法:

    打开 forum/forumdisplay_list.htm 模板,将

      1. <a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else}{/if} class="s xst">$thread[subject]</a>
      复制代码



    替换为:

      1. <a href="forum.php?mod=viewthread&tid=$thread[tid]"{$thread[highlight]} {if $thread['isgroup'] == 1 || $thread['forumstick']}target="_blank"{else}onclick="atarget(this)"{/if} class="s xst">$thread[subject]</a>
      复制代码



    修改后,当选中分类时,列表中的帖子链接将为伪静态,但帖子的分页链接仍是动态,还需进行以下修改。

    打开 source/module/forum/forum_forumdisplay.php 文件,将
    1. <a href="forum.php?mod=viewthread&tid=$realtid&".(!empty($multipate_archive) ? "$multipate_archive&" : '')."extra=$extra&page=$i">
    复制代码



    替换为:

      1. <a href="thread-$realtid-$i-1.html">
      复制代码





      1. <a href="forum.php?mod=viewthread&tid=$realtid&".(!empty($multipate_archive) ? "$multipate_archive&" : '')."extra=$extra&page=$thread[pages]">
      复制代码



    替换为:
    1. <a href="thread-$realtid-$thread[pages]-1.html">
    复制代码




    这样,Discuz! X3.4 主题分类和分类信息帖子链接都会为伪静态,有兴趣的站长赶紧试试啊!
    u507651
    d
    0 0
      @ME:   
    发表于 2021-10-26 21:05:15 | 显示全部楼层
    学下了
    u507651
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 马上注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|吉安论坛 ( 赣ICP备2021010355号 )值班电话:13410000095 站点地图

    GMT+8, 2024-7-5 03:13 , Processed in 0.083582 second(s), 30 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表