1. 程式人生 > >DiscuzX3.1標籤(TAG)目錄化偽靜態修改教程(附規則)

DiscuzX3.1標籤(TAG)目錄化偽靜態修改教程(附規則)

使用discuz論壇的站長都知道discuz論壇系統不支援對TAG的偽靜態,網上搜一下Discuz標籤偽靜態教程是很多,但是大多是針對2.5做的修改,今天酷米論壇站長分享一個針對DiscuzX3.1最新版TAG目錄化偽靜態,偽靜態與目錄化偽靜態哪一個好大家可以看看《百度搜索引擎優化指南》v2.1.2,好了廢話不多說,假面教程開始。

首先我們來看看Discuz預設的TAG標籤頁面是什麼樣子的:

標籤首頁:http://www.koomi.cn/misc.php?mod=tag

標籤內容頁:http://www.koomi.cn/misc.php?mod=tag&id=13


然而通過此教程改變以後的地址是:

標籤首頁:
http://www.koomi.cn/tag/

標籤內容頁:http://www.koomi.cn/tag/13.html

下面修改開始,修改前請記得備份需要修改的檔案,養成良好的習慣,我們想來修改帖子文章下面TAG的地址

開啟 \template\default(模板目錄)\forum\viewthread_node_body.htm

查詢:<a title="$var[1]" href="misc.php?mod=tag&id=$var[0]" target="_blank">$var[1]</a>
替換為:<a title="$var[1]" href="tag/$var[0].html" target="_blank">$var[1]</a>


這樣帖子文章下的標籤地址改變了,接著我們修改標籤頁標籤連結的連結。

開啟 \template\default\tag\tag.htm

查詢:<a title="$var[1]" href="misc.php?mod=tag&id=$var[0]" target="_blank">$var[1]</a>
替換為:<a title="$var[1]" href="tag/$var[0].html" target="_blank">$var[1]</a>

這樣標籤頁的連結修改好了,接下來我麼來修改標籤列表頁導航連結。

開啟 \template\default\tag\tagitem.htm


查詢:<a title="$var[1]" href="misc.php?mod=tag&id=$var[0]" target="_blank">$var[1]</a>
替換為:<a title="$var[1]" href="tag/$var[0].html" target="_blank">$var[1]</a>

這樣所有的頁面的連結修改好了接下來我們加入偽靜態規則,目前之支援win2003與Apache

Apache的規則為:

RewriteCond %{QUERY_STRING} ^(.*)$

RewriteRule ^tag/(.+).html$ misc.php?mod=tag&id=$1

RewriteCond %{QUERY_STRING} ^(.*)$

RewriteRule ^tag/$ misc.php?mod=tag

win2003IIS6.0的規則為:

RewriteRule ^(.*)/tag/(.+)\.html*$ $1/misc.php\?mod=tag&id=$2

RewriteRule ^(.*)/tag/*$ $1/misc.php\?mod=tag

PS:以上規則一定要加在最後一條,即

RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5

上面,否則不會成功,這條規則是外掛偽靜態的規則就算你的外掛不需要偽靜態你也要獲取這條規則放到偽靜態檔案裡面然後把本教程的規則放到這條規則的上面,獲取到規則後你可以在SEO偽靜態那裡勾選掉外掛偽靜態。

教程到這裡還沒有完,

Discuz x3.1 預設禁止蜘蛛抓取標籤頁面,解決方法為:

刪除或註釋掉根目錄下misc.php第18行的:$discuz->reject_robot(); 這段程式碼然後開啟robots.txt檔案刪除一下兩條禁止蜘蛛抓去的規則:

Disallow: /misc.php

Disallow: /*?mod=misc*