西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)php教程 → Apache 服務(wù)器下配置URL 靜態(tài)化的 Rewrite 規(guī)則

Apache 服務(wù)器下配置URL 靜態(tài)化的 Rewrite 規(guī)則

相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時間:2011/1/12 14:37:04字體大。A-A+

作者:佚名點擊:667次評論:0次標(biāo)簽: Apache PHP

  • 類型:編程工具大。11.8M語言:中文 評分:4.0
  • 標(biāo)簽:
立即下載
 如何在Apache環(huán)境下配置Rewrite規(guī)則
Apache Rewrite 規(guī)則 環(huán)境 URL 靜態(tài)化是一個利于搜索引擎的設(shè)置,通過 URL 靜態(tài)化,達(dá)到原來是動態(tài)的 PHP 頁面轉(zhuǎn)換為靜態(tài)化的 HTML 頁面,當(dāng)然,這里的靜態(tài)化是一種假靜態(tài),目的只是提高搜索引擎的搜索量,Comsenz 旗下的產(chǎn)品 Discuz!、SupeSite/X-Space、ECShop、SupeV、UCHome 等都支持此功能。當(dāng)然這個功能還需要服務(wù)器環(huán)境的支持,下面介紹一下如何在 Apache 服務(wù)器下配置 URL 靜態(tài)化的 Rewrite 規(guī)則。

當(dāng)然這里分兩種情況,一種是獨立主機(jī)用戶,這部分用戶擁有對主機(jī)的管理權(quán)限,因此配置起來比較方便一些。(注:這里就以 Discuz!6.1.0 的 Rewrite 規(guī)則為例,稍后在后面會列舉出其他產(chǎn)品的 Rewrite 規(guī)則。


首先確定您使用的 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)中加入如下代碼。此時請務(wù)必注意,如果網(wǎng)站使用通過虛擬主機(jī)來定義,請務(wù)必加到虛擬主機(jī)配置,即 <VirtualHost> 中去,如果加在虛擬主機(jī)配置外部將可能無法使用,改好后將 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 的內(nèi)容中加入 --enable-Rewrite=shared,然后再在 Apache 配置文件中加入上述代碼即可。

另外一種用戶是 Apache 虛擬主機(jī)用戶。

在開始以下設(shè)置之前,請首先咨詢您的空間服務(wù)商,空間是否支持 Rewrite 以及是否支持對站點目錄中 .htaccess 的文件解析,否則即便按照下面的方法設(shè)置好了,也無法使用。

檢查論壇所在目錄中是否存在 .htaccess 文件,如果不存在,請手工建立此文件。Win32 系統(tǒng)下,無法直接建立 .htaccess 文件,您可以從其他系統(tǒng)中拷貝一份,或者在 Discuz.net 技術(shù)支持欄目中下載此文件。編輯并修改 .htaccess 文件,添加以下內(nèi)容:
# 將 RewriteEngine 模式打開
RewriteEngine On
# 修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
RewriteBase /discuz
# Rewrite 系統(tǒng)規(guī)則請勿修改
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添加內(nèi)容時,請遵照上面的提示,修改論壇所在的路徑,然后保存。將 .htaccess 文件上傳到論壇所在的目錄中。然后進(jìn)入論壇系統(tǒng)設(shè)置的搜索引擎優(yōu)化,根據(jù)需要開啟 URL 靜態(tài)化功能。

下面簡單介紹一些其他產(chǎn)品的 Rewrite 規(guī)則。

SupeSite/X-Space6.0 UC規(guī)則

Apache 獨立主機(jī)用戶:

<IfModule mod_Rewrite.c>
RewriteEngine On
###Rewrite 系統(tǒng)規(guī)則請勿修改
RewriteRule ^/([0-9]+)/spacelist(.+)$ /index.php?uid/$1/action/spacelist/type$2 [L]
RewriteRule ^/([0-9]+)/viewspace(.+)$ /index.php?uid/$1/action/viewspace/itemid$2 [L]
RewriteRule ^/([0-9]+)/viewbbs(.+)$ /index.php?uid/$1/action/viewbbs/tid$2 [L]
RewriteRule ^/([0-9]+)/(.*)$ /index.php?uid/$1/$2 [L]
RewriteRule ^/([0-9]+)$ /index.php?uid/$1 [L]
RewriteRule ^/action(.+)$ /index.php?action$1 [L]
RewriteRule ^/category(.+)$ /index.php?action/category/catid$1 [L]
RewriteRule ^/viewnews(.+)$ /index.php?action/viewnews/itemid$1 [L]
RewriteRule ^/viewthread(.+)$ /index.php?action/viewthread/tid$1 [L]
RewriteRule ^/mygroup(.+)$ /index.php?action/mygroup/gid$1 [L]
</IfModule>Apache 虛擬主機(jī)用戶:

### 將 RewriteEngine 模式打開
RewriteEngine On
### 修改以下語句中的 /SupeSite 修改為你的SupeSite目錄地址,如果程序放在根目錄中,請將 /SupeSite 修改為 /
RewriteBase /
### Rewrite 系統(tǒng)規(guī)則請勿修改
RewriteRule ^([0-9]+)/spacelist(.+)$ index.php?uid/$1/action/spacelist/type$2 [L]
RewriteRule ^([0-9]+)/viewspace(.+)$ index.php?uid/$1/action/viewspace/itemid$2 [L]
RewriteRule ^([0-9]+)/viewbbs(.+)$ index.php?uid/$1/action/viewbbs/tid$2 [L]
RewriteRule ^([0-9]+)/(.*)$ index.php?uid/$1/$2 [L]
RewriteRule ^([0-9]+)$ index.php?uid/$1 [L]
RewriteRule ^action(.+)$ index.php?action$1 [L]
RewriteRule ^category(.+)$ index.php?action/category/catid$1 [L]
RewriteRule ^viewnews(.+)$ index.php?action/viewnews/itemid$1 [L]
RewriteRule ^viewthread(.+)$ index.php?action/viewthread/tid$1 [L]
RewriteRule ^mygroup(.+)$ index.php?action/mygroup/gid$1 [L]ECShop2.6.0 規(guī)則

Apache 獨立主機(jī)用戶:

<IfModule mod_Rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/index.html$ $1/index.php
RewriteRule ^(.*)/category$ $1/index.php [L]
RewriteRule ^(.*)/feed-c([0-9]+).xml$ $1/feed.php?cat=$2 [L]
RewriteRule ^(.*)/feed-b([0-9]+).xml$ $1/feed.php?brand=$2 [L]
RewriteRule ^(.*)/feed.xml$ $1/feed.php
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6&page=$7&sort=$8&order=$9
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)\.html$ $1/category.php?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&page=$4&sort=$5&order=$6
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ $1/category.php?id=$2&brand=$3&page=$4
RewriteRule ^(.*)/category-([0-9]+)-b([0-9]+)(.*)\.html$ $1/category.php?id=$2&brand=$3
RewriteRule ^(.*)/category-([0-9]+)(.*)\.html$ $1/category.php?id=$2
RewriteRule ^(.*)/goods-([0-9]+)(.*)\.html$ $1/goods.php?id=$2
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ $1/article_cat.php?id=$2&page=$3&sort=$4&order=$5
RewriteRule ^(.*)/article_cat-([0-9]+)-([0-9]+)(.*)\.html$ $1/article_cat.php?id=$2&page=$3
RewriteRule ^(.*)/article_cat-([0-9]+)(.*)\.html$ $1/article_cat.php?id=$2
RewriteRule ^(.*)/article-([0-9]+)(.*)\.html$ $1/article.php?id=$2
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html $1/brand.php?id=$2&cat=$3&page=$4&sort=$5&order=$6
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html $1/brand.php?id=$2&cat=$3&page=$4
RewriteRule ^(.*)/brand-([0-9]+)-c([0-9]+)(.*)\.html $1/brand.php?id=$2&cat=$3
RewriteRule ^(.*)/brand-([0-9]+)(.*)\.html $1/brand.php?id=$2
RewriteRule ^(.*)/tag-(.*)\.html $1/search.php?keywords=$2
RewriteRule ^(.*)/snatch-([0-9])\.html$ $1/snatch.php?id=$2
RewriteRule ^(.*)/group_buy-([0-9])\.html$ $1/group_buy.php?act=view&id=$2
</IfModule>Apache 虛擬主機(jī)用戶:

RewriteEngine On
#RewriteBase /
# direct one-word access
RewriteRule ^index\.html$ index\.php [L]
RewriteRule ^category$ index\.php [L]
# access any object by its numeric identifier
RewriteRule ^feed-c([0-9]+)\.xml$ feed\.php\?cat=$1 [L]
RewriteRule ^feed-b([0-9]+)\.xml$ feed\.php\?brand=$1 [L]
RewriteRule ^feed\.xml$ feed\.php [L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2 [QSA,L]
RewriteRule ^category-([0-9]+)(.*)\.html$ category\.php\?id=$1 [QSA,L]
RewriteRule ^goods-([0-9]+)(.*)\.html$ goods\.php\?id=$1 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2 [QSA,L]
RewriteRule ^article_cat-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1 [QSA,L]
RewriteRule ^article-([0-9]+)(.*)\.html$ article\.php\?id=$1 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L]
RewriteRule ^brand-([0-9]+)(.*)\.html brand\.php\?id=$1 [QSA,L]
RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L]
RewriteRule ^snatch-([0-9]+)\.html$ snatch\.php\?id=$1 [QSA,L]
RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L]
RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L]SupeV1.0beta 規(guī)則

Apache 獨立主機(jī)用戶:

<IfModule mod_Rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/ivideo(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-9]+))?\.html$ $1/ivideo.php?tv=$3&ti=$5&tc=$7&page=$9
RewriteRule ^(.*)/ispecial(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-9]+))?\.html$ $1/ispecial.php?tv=$3&ti=$5&tc=$7&page=$9
RewriteRule ^(.*)/icategory\.html$ $1/icategory.php
RewriteRule ^(.*)/category-cid-([0-9]+)(-tag-([^-]*))?(-timelimit-([0-9]+))?(-orderlimit-([0-9]+))?(-page-([0-9]+))?\.html$ $1/category.php?cid=$2&tag=$4&timelimit=$6&orderlimit=$8&page=$10
RewriteRule ^(.*)/vspace-(mid|username)-(.+)\.html$ $1/vspace.php?$2=$3
RewriteRule ^(.*)/video-(vid|ivid)-(.+)\.html$ $1/video.php?$2=$3
RewriteRule ^(.*)/special-spid-([0-9]+)\.html$ $1/special.php?spid=$2
</IfModule>Apache 虛擬主機(jī)用戶:

# 將 RewriteEngine 模式打開
RewriteEngine On
# 修改以下語句中的 /SupeV 為你的播客目錄地址,如果程序放在根目錄中,請將 /SupeV 修改為 /
RewriteBase /SupeV
# Rewrite 系統(tǒng)規(guī)則請勿修改 RewriteRule
RewriteRule ^ivideo(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-9]+))?\.html$ ivideo.php?tv=$2&ti=$4&tc=$6&page=$8
RewriteRule ^ispecial(-tv-([0-9]+))?(-ti-([0-9]+))?(-tc-([0-9]+))?(-page-([0-9]+))?\.html$ ispecial.php?tv=$2&ti=$4&tc=$6&page=$8
RewriteRule ^icategory\.html$ icategory.php
RewriteRule ^category-cid-([0-9]+)(-tag-([^-]*))?(-timelimit-([0-9]+))?(-orderlimit-([0-9]+))?(-page-([0-9]+))?\.html$ category.php?cid=$1&tag=$3&timelimit=$5&orderlimit=$7&page=$9
RewriteRule ^vspace-(mid|username)-(.+)\.html$ vspace.php?$1=$2
RewriteRule ^video-(vid|ivid)-(.+)\.html$ video.php?$1=$2
RewriteRule ^special-spid-([0-9]+)\.html$ special.php?spid=$1UCHome1.0 規(guī)則

Apache 獨立主機(jī)用戶:

RewriteEngine On
RewriteRule ^/(space|network)\-(.+)\.html$ /$1.php?Rewrite=$2 [L]
RewriteRule ^/(space|network)\.html$ /$1.php [L]
RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L] Apache 虛擬主機(jī)用戶:

RewriteEngine On
RewriteBase /
RewriteRule ^(space|network)\-(.+)\.html$ $1.php?Rewrite=$2 [L]
RewriteRule ^(space|network)\.html$ $1.php [L]
RewriteRule ^([0-9]+)$ space.php?uid=$1 [L] 當(dāng)然,在我們每個發(fā)布的程序包中,都有關(guān)于此版本程序?qū)?yīng)的 Rewrite 規(guī)則,大家可以在那里找到相對應(yīng)的 Rewrite 規(guī)則。
    jre下載
    (45)jre下載
    是程序的運行環(huán)境,如果你想想編寫程序那就要裝,是整個的核心,包括了運行環(huán)境工具和基礎(chǔ)類庫。語言由于它的跨平臺性,經(jīng)常是編程語言排行榜的榜首,年月份編程語言排行榜,本月變化較大的是與位置互換,領(lǐng)銜稱霸,份額略有上升。前三甲為。當(dāng)然,如果你只是想在上運行程序,那么裝上環(huán)境就了。,,文件怎么運行如果是完整的可執(zhí)行文件,那么是可以雙擊運行的,前提,你的機(jī)器上一定有合適的版本裝過后文件會被關(guān)聯(lián)到用.打開,,直接...更多>>
    • Java Runtime Environment(JRE7)V7

      05-15 / 26.0M

      推薦理由:java 運行庫 runtime environment 7,安裝了它就可以運行java的程序了。Java語言恐怕是穩(wěn)居網(wǎng)路應(yīng)用程序語言
    • jdk7 64位7u80 官方正式版(Java SE

      08-19 / 139.3M

      推薦理由:JDK是一個開發(fā)環(huán)境,用于構(gòu)建應(yīng)用程序,applet程序,和使用Java編程語言的組成部分。Java Development Kit(
    • Java SE Runtime Environment 88.0

      02-13 / 58.9M

      推薦理由:Java語言恐怕是穩(wěn)居網(wǎng)路應(yīng)用程序語言的首選了,這都要歸功于它高度的安全性以及跨平臺的特性,幾乎在目前所有
    • JDK 6(Java SE Development Kit)6u

      03-10 / 57.9M

      推薦理由:適用于您的計算機(jī)(windows)的 Java 軟件,即 Java Runtime Environment,也稱為 Java Runtime、運行時環(huán)境、
    • Java SE Development Kit (JDK7)7u

      08-19 / 137.5M

      推薦理由:JDK 7u51 發(fā)布,該版本修復(fù)了瀏覽器插件的嚴(yán)重的安全漏洞:CVE-2013-1493,Oracle 強(qiáng)烈建議使用 Java 瀏覽器
    • JRE(Java Runtime Environment)v6.

      05-15 / 13.8M

      推薦理由:JAVA運行必不可少的運行環(huán)境,你只要運行JAVA,必須安裝JRE,目前還沒有別的運行平臺可以代替了,它包括Jav
    JAVA軟件
    (60)JAVA軟件
    軟件下載,編程軟件下載專題有多款適合編程愛好者學(xué)習(xí)使用的軟件,我們提供了適用于開發(fā)者使用的相關(guān)軟件的各個版本跟新的下載地址,以方便各位愛好者使用學(xué)習(xí)。如果您有什么好的編程軟件可以向我們提供分享下載,如果下載的軟件有什么問題也可以向我們提供建議,祝程序員們學(xué)習(xí)愉快軟件開發(fā)其實可以不用其他軟件的。只需要安裝了工具包即可,這個是必須的。并且一定要配置好系統(tǒng)的環(huán)境變量。這個可以到網(wǎng)上去查,網(wǎng)上很多。然后進(jìn)...更多>>

    相關(guān)評論

    閱讀本文后您有什么感想? 已有人給出評價!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評論

    最新評論

    第 1 樓 北京開心網(wǎng) 網(wǎng)友 客人 發(fā)表于: 2011/2/20 16:11:31
    加油

    支持( 0 ) 蓋樓(回復(fù))

    發(fā)表評論 查看所有評論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)