1. 程式人生 > >Discuz!X3.1標籤偽靜態修改和偽靜態規則(完整有用)

Discuz!X3.1標籤偽靜態修改和偽靜態規則(完整有用)

編寫本篇的原因是網上較多描述不清楚的教程,使用了後發現各種問題。對於我們這種菜鳥級的,教程需要思路清晰,表述清楚!下邊是根據網上整理過來的,修改不正確的地方!親測可用了。
教程開始

(一)、偽靜態規則新增
  • WIN的新增(httpd.ini)程式碼:
    1. RewriteRule ^(.*)/tag-(.+)\.html*$ $1/misc.php\?mod=tag&id=$2
    2. RewriteRule ^(.*)/tag\.html*$ $1/misc.php\?mod=tag
    複製程式碼

  • linux系統(.htaccess或httpd.conf)新增程式碼
    1. RewriteCond %{QUERY_STRING} ^(.*)$
    2. RewriteRule ^tag-(.+)\.html$ misc.php?mod=tag&id=$1
    3. RewriteCond %{QUERY_STRING} ^(.*)
    4. $RewriteRule ^tag\.html$ misc.php?mod=tag
    複製程式碼
新增方法: 在原偽靜態最後一行之前新增。我的最後一行規則為
  1. RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1
複製程式碼
一些朋友可能為:
  1. RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5
複製程式碼
看系統而定。 如果不新增在上邊的規則之前,會提示“外掛不存在或已關閉”!!!  

(二)、修改帖子內標籤連結(修改系統檔案建議備份,養成好習慣) X3.1後是 template/default(模板目錄)/forum/viewthread_node_body.htm下載到本地開啟 查詢:
  1. <a title="$var[1]" href="misc.php?mod=tag&id=$var[0]" target="_blank">$var[1]</a>
複製程式碼
替換為:
  1. <a title="$var[1]" href="tag-$var[0].html" target="_blank">$var[1]</a>
複製程式碼
(三)、修改標籤頁(tag.htm)標籤連結 檔案在template/default/tag/tag.htm 查詢:
  1. <a href="misc.php?mod=tag&id=$tag[tagid]" title="$tag[tagname]" target="_blank" class="xi2">$tag[tagname]</a>
複製程式碼
替換為:
  1. <a href="tag-$tag[tagid].html" title="$tag[tagname]" target="_blank" class="xi2">$tag[tagname]</a>
複製程式碼

(四)、修改標籤列表頁導航連結tagitem.htm
檔案在template/default/tag/tagitem.htm 查詢1:
  1. <a href="misc.php?mod=tag">{lang tag}</a>
複製程式碼
替換為:
  1. <a href="tag.html">{lang tag}</a>
複製程式碼
查詢2:
  1. <a href="misc.php?mod=tag&id=$id">$tagname</a>
複製程式碼
替換為:
  1. <a href="tag-$id.html">$tagname</a>
複製程式碼

(五)、最後修改robort.txt讓蜘蛛爬行標籤頁。
  • 刪除或註釋掉根目錄下misc.php的這段程式碼
    1. $discuz->reject_robot();
    複製程式碼
  • robots.txt檔案刪除一下兩條禁止蜘蛛抓去的規則:
    1. Disallow: /misc.phpDisallow: /*?mod=misc*
    複製程式碼
上傳替換,完成修改!這時候就完成了標籤偽靜態了。。。。
測試效果:
http://www.qhbang.com/tag.html http://www.qhbang.com/tag-215.html