Discuz! 7.0.0 Rewrite 配置說明

來源:互聯網
上載者:User
全域 —— Discuz! Rewrite 配置說明

Discuz! URL 靜態化(以下簡稱 URL 靜態化)功能可以將 Discuz! Archiver 及部分常用頁面(如 forumdisplay.php、viewthread.php、viewpro.php 等)進行 URL 靜態化轉換,形成類似 http://www.domain.net/forum-1-1.html 形式的超級連結,從而使論壇內容更容易被搜尋引擎挖掘,提高被收錄的機率。

使用注意事項

您可以通過 系統設定 中 Discuz! 選項 來控制 URL 靜態化 的開啟或關閉及其工作狀態

本功能對伺服器環境有特殊要求,外掛式主控件使用者需要對 Web 服務器增加相應的 Rewrite 規則,因此需要伺服器許可權才可使用。對於虛擬機器主機使用者,您需要向您的空間服務商進行諮詢:空間是否支援 Rewrite 以及是否支援對網站目錄中 .htaccess 的檔案解析,只有滿足這兩條件,URL 靜態化 功能才會生效。詳細的的配置,可以參考一下 http://www.discuz.net/usersguide/advanced_urlrewrite.htm#title 。

開啟 URL 靜態化 後,論壇一些常用連結會變成類似 http://www.domain.net/forum-1-1.html 形式,如果您的伺服器環境不支援或者尚未配置好,訪問這些連結會出現“網頁無法顯示”的錯誤資訊,論壇將無法正常訪問。發生無法訪問的現象時,請您進入管理後台,關閉 URL 靜態化 功能,論壇即可恢複正常狀態。

Discuz! URL 靜態化 功能受到論壇所在伺服器環境的制約,在開啟此功能之前,請根據你的 Web 服務器環境,選擇相應的環境配置方法。錯誤的設定有可能造成伺服器無法啟動或者功能無效。

一、Apache Web Server(外掛式主控件使用者)

首先確定您使用的 Apache 版本,還有是否載入了 mod_rewrite 模組。

Apache 1.x 的使用者請檢查 conf/httpd.conf 中是否存在如下兩段代碼:

LoadModule rewrite_module libexec/mod_rewrite.so<br /> AddModule mod_rewrite.c<br />

Apache 2.x 的使用者請檢查 conf/httpd.conf 中是否存在如下一段代碼:

LoadModule rewrite_module modules/mod_rewrite.so<br />

如果存在,那麼在設定檔(通常就是 conf/httpd.conf)中加入如下代碼。此時請務必注意,如果網站使用通過虛擬機器主機來定義,請務必加到虛擬機器主機配置,即 <VirtualHost> 中去,如果加在虛擬機器主機配置外部將可能無法使用。改好後將 Apache 重啟。

<IfModule mod_rewrite.c><br /> RewriteEngine On<br /> RewriteRule ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)$ $1/archiver/index.php?$2<br /> RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)/.html$ $1/forumdisplay.php?fid=$2&page=$3<br /> RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3<br /> RewriteRule ^(.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3<br /> RewriteRule ^(.*)/tag-(.+)/.html$ $1/tag.php?name=$2<br /></IfModule><br />

如果沒有安裝 mod_rewrite,您可以重新編譯 Apache,並在原有 configure 的內容中加入 --enable-rewrite=shared,然後再在 Apache 設定檔中加入上述代碼即可。

二、Apache Web Server(虛擬機器主機使用者)

在開始以下設定之前,請首先諮詢您的空間服務商,空間是否支援 Rewrite 以及是否支援對網站目錄中 .htaccess 的檔案解析,否則即便按照下面的方法設定好了,也無法使用。

檢查論壇所在目錄中是否存在 .htaccess 檔案,如果不存在,請手工建立此檔案。Win32 系統下,無法直接建立 .htaccess 檔案,您可以從其他系統中拷貝一份,或者在 Discuz.net 支援人員欄目中下載此檔案。編輯並修改 .htaccess 檔案,添加以下內容

# 將 RewriteEngine 模式開啟<br />RewriteEngine On</p><p># 修改以下語句中的 /discuz 為你的論壇目錄位址,如果程式放在根目錄中,請將 /discuz 修改為 /<br />RewriteBase /discuz</p><p># Rewrite 系統規則請勿修改<br />RewriteRule ^archiver/((fid|tid)-[/w/-]+/.html)$ archiver/index.php?$1<br />RewriteRule ^forum-([0-9]+)-([0-9]+)/.html$ forumdisplay.php?fid=$1&page=$2<br />RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ viewthread.php?tid=$1&extra=page/%3D$3&page=$2<br />RewriteRule ^space-(username|uid)-(.+)/.html$ space.php?$1=$2<br />RewriteRule ^tag-(.+)/.html$ tag.php?name=$1<br />

新增內容時,請遵照上面的提示,修改論壇所在的路徑,然後儲存。將 .htaccess 檔案上傳到論壇所在的目錄中。然後進入論壇系統設的搜尋引擎最佳化,根據需要開啟 URL 靜態化功能。

三、IIS Web Server(外掛式主控件使用者)

首先在 IIS 的 Isapi 上添加這個篩選器,篩選器名稱為 Rewrite ,可執行檔選擇 Rewrite.dll ,重新啟動 IIS。附件中 httpd.ini 已經設定好,其中內容如下:

[ISAPI_Rewrite]</p><p># 3600 = 1 hour<br />CacheClockRate 3600</p><p>RepeatLimit 32</p><p># Protect httpd.ini and httpd.parse.errors files<br /># from accessing through HTTP<br />RewriteRule ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)/?*(.*)$ $1/archiver/index/.php/?$2&$4<br />RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)/.html/?*(.*)$ $1/forumdisplay/.php/?fid=$2&page=$3&$4<br />RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html/?*(.*)$ $1/viewthread/.php/?tid=$2&extra=page/%3D$4&page=$3&$4<br />RewriteRule ^(.*)/space-(username|uid)-(.+)/.html/?*(.*)$ $1/space/.php/?$2=$3&$4<br />RewriteRule ^(.*)/tag-(.+)/.html/?*(.*)$ $1/tag/.php/?name=$2&$3<br />

然後進入論壇系統設定的搜尋引擎最佳化,根據需要開啟 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)?*(.*)$<br /> if matched then<br /> set URL = $1/archiver/index.php?$2&$4<br /> endif<br /> match URL into $ with ^(.*)/forum-([0-9]+)-([0-9]+)/.html?*(.*)$<br /> if matched then<br /> set URL = $1/forumdisplay.php?fid=$2&page=$3&$4<br /> endif<br /> match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html?*(.*)$<br /> if matched then<br /> set URL = $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3&$4<br /> endif<br /> match URL into $ with ^(.*)/space-(username|uid)-(.+?)/.html?*(.*)$<br /> if matched then<br /> set URL = $1/space.php?$2=$3&$4<br /> endif<br /> match URL into $ with ^(.*)/tag-(.+?)/.html?*(.*)$<br /> if matched then<br /> set URL = $1/tag.php?name=$2$3<br /> endif<br />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.