飞多多小程序 发表于 2020-12-14 13:41:50

Discuz! X3.1主题分类伪静态设置方法(无需插件)

Discuz! X3.1主题分类伪静态设置方法(无需插件)


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

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

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

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

1.修改forumdisplay.htm文件中<li><a href="forum.php?mod=forumdisplay&fid=$_G&filter=typeid&typeid=$id$forumdisplayadd{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}">修改为:
<li><a href="forumtype-$_G-$id-$page.html{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}">

2.接下来再打开forumdisplay_list.htm的源代码:默认主题一般在162行,如你的主题有修改过模板,以你的主题文件为准找到:
<a href="forum.php?mod=viewthread&tid=$thread&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst">$thread</a>
修改为:
<a href="forum.php?mod=viewthread&tid=$thread{if $_G['gp_archiveid']}&archiveid={$_G['gp_archiveid']}{/if}"$thread{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst">$thread</a>

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

①打开source\module\forum\forum_forumdisplay.php,查找
forum.php?mod=forumdisplay&fid='.$_G['fid'].'&filter=typeid&typeid='.$thread['typeid'].'

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

②、打开模板目录viewthread.htm,查找
forum.php?mod=forumdisplay&fid=$_G&filter=typeid&typeid=$_G

注意【有可以找不到】,因为&这个符号有的代码是用amp的那个转义字符代替了。

替换为:
forumtype-$_G-{$_G}-1.html

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

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

.htaccess 伪静态规则 请在末二行的上面增加:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^forumtype-(\w+)-(\w+)-(+)\.html$ forum.php?mod=forumdisplay&fid=$1&filter=typeid&typeid=$2&page=$3&%1

注意:增加的规则不能放最后,特别是 不能 放在插件规则的最后【必须要在末二行的上面】,不然访问分类伪静态会出现“插件不存在或删除”的错误。

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


web.config 伪静态规则
<rule name="forum_forumtype">
<match url="^(.*/)*forumtype-(\w+)-(\w+)-(+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type="Rewrite" url="{R:1}/forum.php\?mod=forumdisplay&fid={R:2}&filter=typeid&typeid={R:3}&page={R:4}&{R:5}" />
</rule>


页: [1]
查看完整版本: Discuz! X3.1主题分类伪静态设置方法(无需插件)