偽靜態設置可以說對搜索引擎會友好很多了,有人說偽靜態為真正的靜態還要好,下面我就聽了這話來把一個discuz x2.5論壇設置整站為偽靜態了,下面把例子與各位分享.
一、discuz x2論壇首頁“最后發表”帖子鏈接靜態化
現在還沒有找到完美的解決方法,不過通過這樣做還是基本實現我想要的形式,有兩種方法,各有各的不足.
方法1、/source/module/forum/ 下的forum_redirect.php,代碼如下:
- //把
- dheader(‘Location: forum.php?mod=viewthread&tid=’.$_G['tid'].$pageadd.’#lastpost’);
- //換成
- header("HTTP/1.1 301 Moved Permanently");
- dheader(‘Location:thread-’.$_G['tid'].’-’.$page.’-1.html#lastpost’);
雖然首頁顯示是動態地址,但是點擊就會301跳轉到靜態頁,這個方法是定死的,取消了偽靜態設置還是會跳轉到這個偽靜態地址,所以一定開啟了偽靜態而且必須是系統默認的方式,才可以這樣修改.
方法2、這個方法是直接修改模板discuz.htm中的如下代碼:
- forum.php?mod=redirect&tid=$forum[lastpost][tid]&goto=lastpost#lastpost
- //換成
- forum.php?mod=viewthread&tid=$forum[lastpost][tid]
一共有三處,這個方法可是完美支持自動判斷網站是偽靜態還是動態,不足之處是點擊不會跳轉到最后回復的帖子,只會跳轉到最后回復的主題.
二、discuz x2“上一主題、下一主題”鏈接靜態化
利用$_G[tid]-1 和 $_G[tid]+1 來做連接,打開viewthread.htm文件,查找如下代碼:
- <a href="forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]" title="{lang last_thread}"><img src="{IMGDIR}/thread-prev.png" alt="{lang last_thread}" class="vm" /></a>
- <a href="forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]" title="{lang next_thread}"><img src="{IMGDIR}/thread-next.png" alt="{lang next_thread}" class="vm" /></a>
- //修改為:
- <!--{eval $up_thread=$_G[tid]-1;$down_thread=$_G[tid]+1;}-->
- <a href="thread-$up_thread-1-1.html" rel="nofollow" title="{lang last_thread}"><img src="{IMGDIR}/thread-prev.png" alt="{lang last_thread}" class="vm" /></a>//開源軟件:Vevb.com
- <a href="thread-$down_thread-1-1.html" rel="nofollow" title="{lang next_thread}"><img src="{IMGDIR}/thread-next.png" alt="{lang next_thread}" class="vm" /></a>
如果主題被刪除就找不到了用這種方法.
三、Discuz X2.0論壇帖“復制鏈接”偽靜態實現方法
打開 /template/default/forum/viewthread.htm 在大約200行左右找到以下代碼:
- forum.php?mod=viewthread&tid=$_G[tid]$fromuid
- //換成
- forum.php?mod=viewthread&tid=$_G[tid]
- //就可以了
四、discuz x2帖子列表頁默認打開修改為新窗口打開
discuz x2帖子列表默認打開是本窗口打開的,不符合國內用戶使用習慣,最正規的修改如下面兩個步驟.
1:根目錄/static/js/forum.js,找到 atarget函數,改成如下代碼:
- function atarget(obj) {
- obj.target = getcookie('atarget') ? '': '_blank';
- }
2:把‘打開新窗口’改成‘本窗口打開’ 修改如下.
根目錄/template/default/forum/forumdisplay_list.html文件中,找到如下代碼:
- <span id="atarget" {if !emptyempty($_G['cookie']['atarget'])}onclick="setatarget(0)" class="y atarget_1"{else}onclick="setatarget(1)" class="y"{/if} title="{lang new_window_thread}">{lang new_window}</span>
- //用下邊的替換即可
- <span id="atarget" {if !emptyempty($_G['cookie']['atarget'])}onclick="setatarget(0)" class="y atarget_1"{else}onclick="setatarget(1)" class="y"{/if} title="本窗口打開帖子">本窗口</span>
五、discuz x2 rss輸出鏈接的靜態化
今天(2011-12-11)又發現一個discuz x2 url地址不規范的地方,就是rss的地址不能自動判斷網站設置的是靜態還是動態,一律會輸出動態的樣式,那對于開啟了偽靜態的朋友來說是個很不好的地方,如何將rss輸出結果變成靜態化呢,下面是具體修改步驟:
打開source/module/forum/forum_rss.php,代碼如下:
1、論壇首頁URL標準化:如果不需要標準的人不用修改:
- //把
- <link>{$_G[siteurl]}forum.php</link>
- //改為
- <link>{$_G[siteurl]}</link>
2、主題列表頁URL偽靜態:把:
- <link>{$_G[siteurl]}forum.php?mod=forumdisplay&fid=$rssfid</link>
- //改為
- <link>$_G[siteurl]forum-$forum[fid]-1.html</link>
3、帖子內容頁URL偽靜態:把
- <link>$_G[siteurl]forum.php?mod=viewthread&tid=$thread[tid]</link>
- //改為
- <link>$_G[siteurl]thread-$thread[tid]-1-1.html</link>
六、discuz x2 帖子鏈接統一(帖子鏈接唯一化)
開啟了偽靜態的帖子鏈接是這樣的形式:thread-x-y-z.html,其中x是帖子的id(固定不變的),y是帖子的頁數(也是固定的),z是帖子所在列表頁的頁數(這個是變化的,隨著帖子回復或者新帖的加入,所處位置就會變化),如何讓z不變呢,可能通過修改template/default/forum/forumdisplay_list.htm解決,修改后雖然帖子的url統一了,但是在帖子頁里點擊“返回列表”,返回的是列表第一頁而不是帖子所在的列表頁.
找到如下:
- <a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_G['gp_archiveid']}archiveid={$_G['gp_archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="xst" >$thread[subject]</a>
- //修改為 //開源軟件:Vevb.com
- <a href="forum.php?mod=viewthread&tid=$thread[tid]" $thread[highlight]{if $thread['isgroup'] == 1} target="_blank"{/if} onclick="atarget(this)" class="xst">$thread[subject]</a>
7.下一主題上一主題圖片修改.
8.開啟偽靜態.
全局,seo設置.
論壇主題列表頁 {fid},{page}
論壇主題內容頁 {tid},{page},{prevpage}
可用上打勾.
然后 點 查看當前的 Rewrite 規則.
URL 靜態化 完工 ..
新聞熱點
疑難解答