TShopping

 找回密碼
 註冊
搜索
查看: 1676|回復: 0
打印 上一主題 下一主題

[X2.0] 如何為 Discuz! X2 Apache 2.X配置偽靜態

[複製鏈接]
跳轉到指定樓層
1#
發表於 2011-11-30 18:34:04 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
URL 靜態化是一個有利于于搜索引擎的設置,通過 URL 靜態化,達到原來是動態的 PHP 頁面轉換為靜態化的 HTML 頁面,可以提高搜索引擎抓取,當然,這裡的靜態化是一種假靜態,目的只是提高搜索引擎的搜索量,下面主要介紹配置方法。
分兩種情況,一種是獨立主機用戶,這部分用戶擁有對主機的管理權限,因此配置起來比較方便一些。

首先確定您使用的 Apache 版本,及是否加載了 mod_Rewrite 模塊。
Apache 1.x 的用戶請檢查 conf/httpd.conf 中是否存在如下兩段代碼:
LoadModule Rewrite_module libexec/mod_Rewrite.so
AddModule mod_Rewrite.c Apache 2.x 的用戶請檢查 conf/httpd.conf 中是否存在如下一段代碼:
LoadModule Rewrite_module modules/mod_Rewrite.so
如果存在,那麼在配置文件(通常就是 conf/httpd.conf)中加入如下代碼。此時請務必注意,如果網站使用通過虛擬主機來定義,請務必加到虛擬主機配置,即 <VirtualHost> 中去,如果加在虛擬主機配置外部將可能無法使用,改好後將 Apache 重啟。

一、Apache Web Server(獨立主機用戶)

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteCond %{QUERY_STRING} ^(.*)$
  4. RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
  5. RewriteCond %{QUERY_STRING} ^(.*)$
  6. RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
  7. RewriteCond %{QUERY_STRING} ^(.*)$
  8. RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
  9. RewriteCond %{QUERY_STRING} ^(.*)$
  10. RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
  11. RewriteCond %{QUERY_STRING} ^(.*)$
  12. RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
  13. RewriteCond %{QUERY_STRING} ^(.*)$
  14. RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1
  15. </IfModule>
複製代碼
如果沒有安裝 mod_Rewrite,您可以重新編譯 Apache,並在原有 configure 的內容中加入 --enable-Rewrite=shared,然後再在Apache 配置文件中加入上述代碼即可。

二、Apache Web Server(虛擬主機用戶)

在開始以下設置之前,請首先咨詢您的空間服務商,空間是否支持 Rewrite 以及是否支持對站點目錄中 .htaccess 的文件解析,否則即便按照下面的方法設置好了,也無法使用。
檢查論壇所在目錄中是否存在 .htaccess 文件,如果不存在,請手工建立此文件。Win32 系統下,無法直接建立 .htaccess 文件,您可以從其他系統中拷貝一份,編輯並修改 .htaccess 文件,添加以下內容:

  1. # 將 RewriteEngine 模式打開
  2. RewriteEngine On
  3. # 修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
  4. RewriteBase /discuz
  5. # Rewrite 系統規則請勿修改
  6. RewriteCond %{QUERY_STRING} ^(.*)$
  7. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
  8. RewriteCond %{QUERY_STRING} ^(.*)$
  9. RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
  10. RewriteCond %{QUERY_STRING} ^(.*)$
  11. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
  12. RewriteCond %{QUERY_STRING} ^(.*)$
  13. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
  14. RewriteCond %{QUERY_STRING} ^(.*)$
  15. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
  16. RewriteCond %{QUERY_STRING} ^(.*)$
  17. RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
複製代碼

.htaccess文件放在你論壇的根目錄

要將這個BUG解決先,打開../source/function/function_core.php這個文件。
查找代碼:
$_G['setting']['output']['preg']['search'] = str_replace('\{CURHOST\}', preg_quote($_G['siteurl']), $_G['setting']['output']['preg']['search']);換成:
$_G['setting']['output']['preg']['search'] = str_replace('\{CURHOST\}', preg_quote($_G['siteurl'], '/'), $_G['setting']['output']['preg']['search']);


 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-26 04:01 , Processed in 0.064731 second(s), 18 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表