allthebest 發表於 2019-7-21 19:59:28

Discuz! X3.4主题分类和分类信息伪静态设置方法(亲测可用)

网上99%都是不完善和残缺的 或者各种不兼容,有的论坛还复制别人的DZ3.2版本的伪静态方法说是支持3.4版本的,全是让人浪费时间。<br /><br /><strong><font size="5">A、主题分类伪静态设置方法:</font></strong><br /><br />准备好修改的模板文件:forumdisplay.htm和forumdisplay_list.htm<br /><br />这两个文件都在 \template\default\forum 的目录下(有修改过discuz模板,以你的主题文件路径为准,如/template/主题模板文件夹/forum)。<br /><br />我们要先修改主题分类的:打开forumdisplay.htm的源代码:<br /><br />默认主题一般在415行,当然如你的主题有修改过discuz模板,以你的主题文件路径为准<br /><br />1.修改forumdisplay.htm文件中<br /><br /><ol><li>&lt;li&gt;&lt;a href=&quot;forum.php?mod=forumdisplay&amp;fid=$_G&amp;filter=typeid&amp;typeid=$id$forumdisplayadd{if $_GET['archiveid']}&amp;archiveid={$_GET['archiveid']}{/if}&quot;&gt;</ol><br /><br />修改为:<br /><br /><ol><li>&lt;li&gt;&lt;a href=&quot;forumtype-$_G-$id-$page.html{if $_GET['archiveid']}&amp;archiveid={$_GET['archiveid']}{/if}&quot;&gt;</ol><br /><br />2.接下来再打开forumdisplay_list.htm的源代码:默认主题一般在162行,如你的主题有修改过模板,以你的主题文件为准找到:<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$thread&amp;{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&amp;{/if}extra=$extra&quot;$thread{if $thread['isgroup'] == 1 || $thread['forumstick']} target=&quot;_blank&quot;{else} onclick=&quot;atarget(this)&quot;{/if} class=&quot;s xst&quot;&gt;$thread&lt;/a&gt;</ol><br /><br />修改为:<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$thread{if $_G['gp_archiveid']}&amp;archiveid={$_G['gp_archiveid']}{/if}&quot;$thread{if $thread['isgroup'] == 1 || $thread['forumstick']} target=&quot;_blank&quot;{else} onclick=&quot;atarget(this)&quot;{/if} class=&quot;s xst&quot;&gt;$thread&lt;/a&gt;</ol><br /><br />3.主题类别前缀【只显示文字】,<font color="Red">2个地方需要修改</font><br /><br />i、打开source\module\forum\forum_forumdisplay.php,查找<br /><br /><ol><li>forum.php?mod=forumdisplay&amp;fid='.$_G['fid'].'&amp;filter=typeid&amp;typeid='.$thread['typeid'].'</ol><br /><br />替换为:<br /><br /><ol><li>forumtype-'.$_G['fid'].'-'.$thread['typeid'].'-1.html</ol><br /><br />ii、打开模板目录viewthread.htm,查找<br /><br /><ol><li>forum.php?mod=forumdisplay&amp;fid=$_G&amp;filter=typeid&amp;typeid=$_G</ol><br /><br />替换为:<br /><br /><ol><li>forumtype-$_G-{$_G}-1.html</ol><br /><br />最后我们要把主题分类的伪静态规则添加到相应文件中,规则如下<br /><br />(因为环境问题,只测试了.htaccess,其它请自行测试):<br /><br />.<strong>htaccess 伪静态规则</strong> 请在<font color="Red">RewriteRule ^forum-(\w+)-(+)\.html$ forum.php?mod=forumdisplay&amp;fid=$1&amp;page=$2&amp;%1</font>下面增加:<br /><br /><ol><li>RewriteCond %{QUERY_STRING} ^(.*)$<br /><li>RewriteRule ^forumtype-(\w+)-(\w+)-(+)\.html$ forum.php?mod=forumdisplay&amp;fid=$1&amp;filter=typeid&amp;typeid=$2&amp;page=$3&amp;%1</ol><br /><br /><font color="Red">注意:</font>增加的规则不能放最后,特别是不能 不能 不能放在插件规则RewriteRule ^(+*)-(+)\.html$ plugin.php?id=$1 :$2&amp;%1之后,不然访问分类伪静态会出现“插件不存在或删除”的错误。<br /><br /><strong>httpd.ini 伪静态规则</strong><br /><br /><ol><li>RewriteRule ^(.*)/forumtype-(\w+)-(\w+)-(+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&amp;fid=$2&amp;filter=typeid&amp;typeid=$3&amp;page=$4&amp;$5</ol><br /><br /><strong>web.config 伪静态规则</strong><br /><br /><ol><li>&lt;rule name=&quot;forum_forumtype&quot;&gt;<br /><li>&lt;match url=&quot;^(.*/)*forumtype-(\w+)-(\w+)-(+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; /&gt;<br /><li>&lt;action type=&quot;Rewrite&quot; url=&quot;{R:1}/forum.php\?mod=forumdisplay&amp;fid={R:2}&amp;filter=typeid&amp;typeid={R:3}&amp;page={R:4}&amp;{R:5}&quot; /&gt;<br /><li>&lt;/rule&gt;</ol><br /><br /><strong><font size="5">B、分类信息列表内的帖子设置伪静态方法:</font></strong><br /><br />打开 forum/forumdisplay_list.htm 模板,将<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$thread&amp;{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&amp;{/if}extra=$extra&quot;$thread{if $thread['isgroup'] == 1 || $thread['forumstick']} target=&quot;_blank&quot;{else}{/if} class=&quot;s xst&quot;&gt;$thread&lt;/a&gt;</ol><br /><br />替换为:<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$thread&quot;{$thread} {if $thread['isgroup'] == 1 || $thread['forumstick']}target=&quot;_blank&quot;{else}onclick=&quot;atarget(this)&quot;{/if} class=&quot;s xst&quot;&gt;$thread&lt;/a&gt;</ol><br /><br />修改后,当选中分类时,列表中的帖子链接将为伪静态,但帖子的分页链接仍是动态,还需进行以下修改。<br /><br />打开 source/module/forum/forum_forumdisplay.php 文件,将<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$realtid&amp;&quot;.(!empty($multipate_archive) ? &quot;$multipate_archive&amp;&quot; : '').&quot;extra=$extra&amp;page=$i&quot;&gt;</ol><br /><br />替换为:<br /><br /><ol><li>&lt;a href=&quot;thread-$realtid-$i-1.html&quot;&gt;</ol><br /><br />将<br /><br /><ol><li>&lt;a href=&quot;forum.php?mod=viewthread&amp;tid=$realtid&amp;&quot;.(!empty($multipate_archive) ? &quot;$multipate_archive&amp;&quot; : '').&quot;extra=$extra&amp;page=$thread&quot;&gt;</ol><br /><br />替换为:<br /><br /><ol><li>&lt;a href=&quot;thread-$realtid-$thread-1.html&quot;&gt;</ol><br /><br /><br />这样,Discuz! X3.4 主题分类和分类信息帖子链接都会为伪静态,有兴趣的站长赶紧试试啊!<br /><br /><br />主题<em>, </em>文件<em>, </em>静态<em>, </em>模板<em>, </em>方法

pmxsd 發表於 2019-7-21 21:08:41

感谢老大分享<br />

sosoba 發表於 2019-7-23 18:50:34

感谢分享,学习了

sosoba 發表於 2019-7-23 23:44:50

测试了一下,A类 主题分类伪静态设置方法 亲测有效<br /><br />B类的 不行 设置修改后&nbsp; &nbsp;分类信息 列表内的帖子还是 动态&nbsp;&nbsp;列表分页 也是动态<br /><br /><br />不过还是谢谢你的分享

sosoba 發表於 2019-7-25 13:50:59

<font size="5">A、主题分类伪静态设置方法&nbsp;&nbsp;这个方法可以用,测试过了,生效了</font><br /><font size="5">非常感谢</font><br /><font size="5">B类的方法测试了下 不生效,不知道原因出在哪里</font><br />

allthebest 發表於 2019-7-25 18:46:52

<br />大概是第三方模版问题<br /><br />

sosoba 發表於 2019-7-26 13:39:24

<br />有这个可能 我还在测试 不过感谢你的教程,非常棒

青苹果 發表於 2020-1-9 07:10:14

感谢大佬分享

zhsyn 發表於 2020-1-9 14:44:56

学习了,很好的分享

yehui2512 發表於 2020-9-14 20:29:34

学习了,很好的分享
頁: [1]
查看完整版本: Discuz! X3.4主题分类和分类信息伪静态设置方法(亲测可用)