Discuz! URL 靜態化 功能受到論壇所在服務器環境的制約,在開啟此功能之前,請根據你的 Web 服務器環境,選擇相應的環境配置方法。
錯誤的設置有可能造成服務器無法啟動或者功能無效。以下僅提供 Apache 和 Zeus 的配置方法,IIS 或其他 Web 服務器
您可根據原理自行修改。
Apache Web Server(獨立主機用戶)
首先確定您使用的 Apache 版本,及是否加載了 mod_rewrite 模塊。
Apache 1.x 的用戶請檢查 conf/httpd.conf 中是否存在如下兩段代碼:
LoadModule rewrite_module libexec/mod_rewrite.so
Apache 2.x 的用戶請檢查 conf/httpd.conf 中是否存在如下一段代碼:
LoadModule rewrite_module modules/mod_rewrite.so
如果存在,那麼在配置文件(通常就是 conf/httpd.conf)中加入如下代碼。此時請務必注意,如果網站使用通過虛擬主機來定義,請務必
加到虛擬主機配置,即 <VirtualHost> 中去,如果加在虛擬主機配置外部將可能無法使用。改好後然後將 Apache 重啟。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3
RewriteRule ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2
</IfModule>
如果沒有安裝 mod_rewrite,您可以重新編譯 Apache,並在原有 configure 的內容中加入 --enable-rewrite=shared,然後再在 Apache
配置文件中加入上述代碼即可。
Apache Web Server(虛擬主機用戶)
在開始以下設置之前,請首先咨詢您的空間服務商,空間是否支持 Rewrite 以及是否支持對站點目錄中 .htaccess 的文件解析,否則即便按照下面的方法設置好了,
也無法使用。
檢查論壇所在目錄中是否存在 .htaccess 文件,如果不存在,請手工建立此文件。Win32 系統下,無法直接建立 .htaccess 文件,您可以從其他系統中拷貝一份,
或者在 Discuz.net 技術支持欄目中下載此文件。編輯並修改 .htaccess 文件,添加以下內容
# 將 RewriteEngine 模式打開
RewriteEngine On
# 修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
RewriteBase /discuz
# Rewrite 系統規則請勿修改
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1
添加內容時,請遵照上面的提示,修改論壇所在的路徑,然後保存。將 .htaccess 文件上傳到論壇所在的目錄中。然後進入論壇系統設置的搜索引擎優化,根據需要開啟 URL 靜態化功能。
IIS Web Server(獨立主機用戶)
首先在 IIS 的 Isapi 上添加這個篩選器,篩選器名稱為 Rewrite ,可執行文件選擇 Rewrite.dll ,重新啟動 IIS。附件中 httpd.ini 已經設置好,其中內容如下:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
RewriteRule ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)\?*(.*)$ $1/archiver/index\.php\?$2&$4
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/forumdisplay\.php\?fid=$2&page=$3&$4
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/viewthread\.php\?tid=$2&extra=page\%3D$4&page=$3&$4
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html\?*(.*)$ $1/space\.php\?$2=$3&$4
RewriteRule ^(.*)/tag-(.+)\.html\?*(.*)$ $1/tag\.php\?name=$2&$3
然後進入論壇系統設置的搜索引擎優化,根據需要開啟 URL 靜態化功能。
附件下載地址:http://www.discuz.net/attachment.php?aid=124274
Zeus Web Server
在虛擬主機配置中找到 Request Rewriting,在 Rewrite Script 中寫入以下內容,然後 Apply changes 並 make it
take effect。
match URL into $ with ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)?*(.*)$
if matched then
set URL = $1/archiver/index.php?$2&$4
endif
match URL into $ with ^(.*)/forum-([0-9]+)-([0-9]+)\.html?*(.*)$
if matched then
set URL = $1/forumdisplay.php?fid=$2&page=$3&$4
endif
match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html?*(.*)$
if matched then
set URL = $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3&$4
endif
match URL into $ with ^(.*)/space-(username|uid)-(.+?)\.html?*(.*)$
if matched then
set URL = $1/space.php?$2=$3&$4
endif
match URL into $ with ^(.*)/tag-(.+?)\.html?*(.*)$
if matched then
set URL = $1/tag.php?name=$2$3
endif
修改完服務器配置後請進入論壇 系統設置,打開 URL 靜態化 功能,測試功能是否正常。如果出現問題,請仔細檢查你所做的每一步。
|