apache中偽靜態(tài)配置和使用(Apache虛擬主機下Discuz偽靜態(tài))
更新時間:2012年01月03日 12:09:36 作者:
apache中偽靜態(tài)配置和使用(Apache虛擬主機下Discuz偽靜態(tài)),需要的朋友可以參考下。
一 打開 Apache 的配置文件 httpd.conf 。
二 將#LoadModule rewrite_module modules/mod_rewrite前面的#去掉
三 在 httpd.conf中添加:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+\.html
RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+)\.html$ $1.php?__is_apache_rewrite=1&__rewrite_arg=$2
</IfModule>
四 要實現(xiàn)asp帖子URL到php帖子的映射,在 第三步的<IfModule mod_rewrite.c>和</IfModule>之間添加:
RewriteMap tolowercase int:tolower
RewriteCond %{QUERY_STRING} (?:boardid|page|id|replyid|star|skin)\=\d+ [NC]
RewriteRule ^(.*(?:index|dispbbs))\.asp$ $1.php?${tolowercase:%{QUERY_STRING}}&__is_apache_rewrite=1
五 保存httpd.conf并重啟Apache。
六、mod_rewrite 簡介
Rewirte主要的功能就是實現(xiàn)URL的跳轉(zhuǎn)和隱藏真實地址,基于Perl語言的正則表達式規(guī)范。平時幫助我們實現(xiàn)偽靜態(tài),擬目錄,域名跳轉(zhuǎn),防止盜鏈等等
七、mod_rewrite 規(guī)則的使用
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com [NC]
RewriteRule ^/(.*) http://www.php100.com/ [L]
--------
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]
八、mod_rewrite 規(guī)則修正符
1) R 強制外部重定向
2) F 禁用URL,返回403HTTP狀態(tài)碼。
3) G 強制URL為GONE,返回410HTTP狀態(tài)碼。
4) P 強制使用代理轉(zhuǎn)發(fā)。
5) L 表明當(dāng)前規(guī)則是最后一條規(guī)則,停止分析以后規(guī)則的重寫。
6) N 重新從第一條規(guī)則開始運行重寫過程。
7) C 與下一條規(guī)則關(guān)聯(lián)8) T=MIME-type(force MIME type) 強制MIME類型
9) NS 只用于不是內(nèi)部子請求
10) NC 不區(qū)分大小寫
11) QSA 追加請求字符串
12) NE 不在輸出轉(zhuǎn)義特殊字符 \%3d$1 等價于 =$1
Apache虛擬主機下使用Rewrite實現(xiàn)Discuz偽靜態(tài)的配置
第一步 :當(dāng)然是配置Apache支持Rewrite功能,這個不多說了,就是:
LoadModule rewrite_module modules/mod_rewrite.so
原來有注釋的就去掉注釋,原來沒有的添加上。
上面的配置中:
1.Options FollowSymLinks 這一步的配置必須有。
2.AllowOverride all 原來None的要改成all。
這兩個配置缺一不可。
第三步 ,大家就比較熟悉了也不多說了,
就是在對應(yīng)的目錄下面添加.htaccess文件,下面以discuz為例說明:
RewriteEngine On
RewriteBase /
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
第四步 :配置Discuz使用偽靜態(tài):
登錄后臺管理,進入“全局”=》“優(yōu)化配置”=》“搜索引擎優(yōu)化”在原來URL靜態(tài)化的地方選中,然后提交即可。
配置完畢,去discuz前臺訪問就可以了。原來的php都變成html了。

在apache配置文件中設(shè)置
<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 ^/home/(space|network)-(.+)\.html$ /home/$1\.php\?rewrite=$2
RewriteRule ^/home/(space|network)\.html$ /home/$1\.php
RewriteRule ^/home/([0-9]+)$ /home/space\.php\?uid=$1
RewriteRule ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2
</IfModule>
此文適用于Apache虛擬主機用戶。
在開始以下設(shè)置之前,首先應(yīng)該確認服務(wù)器支持mod_rewrite以及支持對站點目錄中.htaccess的文件解析,否則即便按照下面的方法設(shè)置好了,也無法使用。點擊查看Apache下開啟mod_rewrite的方法。
Apache下開啟mod_rewrite
服務(wù)器環(huán)境:Windows Server 2003 SP2 + Apache 2.0.59
開啟方法:
用文本編輯器打開Apache安裝目錄\conf\httpd.conf,找到“#LoadModule rewrite_module modules/mod_rewrite.so”這行,去掉前面的“#”;繼續(xù)查找“AllowOverride None”,修改為“AllowOverride All”;然后,重啟Apache即可。
檢查論壇所在目錄中是否存在.htaccess 文件,如果不存在,則手工建立此文件。在Win32系統(tǒng)下,無法直接建立.htaccess 文件,則可以從其他系統(tǒng)中拷貝一份,也可以點擊這里下載我做的一個,解壓縮后即可使用。編輯并修改.htaccess文件,添加以下內(nèi)容 :
# 將 RewriteEngine 模式打開
RewriteEngine On
# 修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
RewriteBase /discuz
# Rewrite 系統(tǒng)規(guī)則請勿修改
RewriteRule ^archiver/([a-z0-9\-]+\.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 ^profile-(username|uid)-(.+)\.html$ viewpro.php?$1=$2
添加內(nèi)容時,請遵照上面的提示,修改論壇所在的路徑,然后保存。將.htaccess文件上傳到論壇所在的目錄中。進入論壇系統(tǒng)設(shè)置,根據(jù)需要開啟URL靜態(tài)化功能。
-=======================================================
注意下面必須得
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
DocumentRoot "E:\aaa\wwwroot"
ServerName *
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.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 ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>
=======================
NameVirtualHost 124.129.183.146
<VirtualHost bbs.jb51.net>
ServerName bbs.jb51.net
DocumentRoot D:/WebSite/phpbbs
<Directory "D:/WebSite/phpbbs">
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.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 ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>
二 將#LoadModule rewrite_module modules/mod_rewrite前面的#去掉
三 在 httpd.conf中添加:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+\.html
RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+)\.html$ $1.php?__is_apache_rewrite=1&__rewrite_arg=$2
</IfModule>
四 要實現(xiàn)asp帖子URL到php帖子的映射,在 第三步的<IfModule mod_rewrite.c>和</IfModule>之間添加:
RewriteMap tolowercase int:tolower
RewriteCond %{QUERY_STRING} (?:boardid|page|id|replyid|star|skin)\=\d+ [NC]
RewriteRule ^(.*(?:index|dispbbs))\.asp$ $1.php?${tolowercase:%{QUERY_STRING}}&__is_apache_rewrite=1
五 保存httpd.conf并重啟Apache。
六、mod_rewrite 簡介
Rewirte主要的功能就是實現(xiàn)URL的跳轉(zhuǎn)和隱藏真實地址,基于Perl語言的正則表達式規(guī)范。平時幫助我們實現(xiàn)偽靜態(tài),擬目錄,域名跳轉(zhuǎn),防止盜鏈等等
七、mod_rewrite 規(guī)則的使用
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com [NC]
RewriteRule ^/(.*) http://www.php100.com/ [L]
--------
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]
八、mod_rewrite 規(guī)則修正符
1) R 強制外部重定向
2) F 禁用URL,返回403HTTP狀態(tài)碼。
3) G 強制URL為GONE,返回410HTTP狀態(tài)碼。
4) P 強制使用代理轉(zhuǎn)發(fā)。
5) L 表明當(dāng)前規(guī)則是最后一條規(guī)則,停止分析以后規(guī)則的重寫。
6) N 重新從第一條規(guī)則開始運行重寫過程。
7) C 與下一條規(guī)則關(guān)聯(lián)8) T=MIME-type(force MIME type) 強制MIME類型
9) NS 只用于不是內(nèi)部子請求
10) NC 不區(qū)分大小寫
11) QSA 追加請求字符串
12) NE 不在輸出轉(zhuǎn)義特殊字符 \%3d$1 等價于 =$1
Apache虛擬主機下使用Rewrite實現(xiàn)Discuz偽靜態(tài)的配置
第一步 :當(dāng)然是配置Apache支持Rewrite功能,這個不多說了,就是:
LoadModule rewrite_module modules/mod_rewrite.so
原來有注釋的就去掉注釋,原來沒有的添加上。
上面的配置中:
1.Options FollowSymLinks 這一步的配置必須有。
2.AllowOverride all 原來None的要改成all。
這兩個配置缺一不可。
第三步 ,大家就比較熟悉了也不多說了,
就是在對應(yīng)的目錄下面添加.htaccess文件,下面以discuz為例說明:
RewriteEngine On
RewriteBase /
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
第四步 :配置Discuz使用偽靜態(tài):
登錄后臺管理,進入“全局”=》“優(yōu)化配置”=》“搜索引擎優(yōu)化”在原來URL靜態(tài)化的地方選中,然后提交即可。
配置完畢,去discuz前臺訪問就可以了。原來的php都變成html了。

在apache配置文件中設(shè)置
復(fù)制代碼 代碼如下:
<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 ^/home/(space|network)-(.+)\.html$ /home/$1\.php\?rewrite=$2
RewriteRule ^/home/(space|network)\.html$ /home/$1\.php
RewriteRule ^/home/([0-9]+)$ /home/space\.php\?uid=$1
RewriteRule ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2
</IfModule>
此文適用于Apache虛擬主機用戶。
在開始以下設(shè)置之前,首先應(yīng)該確認服務(wù)器支持mod_rewrite以及支持對站點目錄中.htaccess的文件解析,否則即便按照下面的方法設(shè)置好了,也無法使用。點擊查看Apache下開啟mod_rewrite的方法。
Apache下開啟mod_rewrite
服務(wù)器環(huán)境:Windows Server 2003 SP2 + Apache 2.0.59
開啟方法:
用文本編輯器打開Apache安裝目錄\conf\httpd.conf,找到“#LoadModule rewrite_module modules/mod_rewrite.so”這行,去掉前面的“#”;繼續(xù)查找“AllowOverride None”,修改為“AllowOverride All”;然后,重啟Apache即可。
檢查論壇所在目錄中是否存在.htaccess 文件,如果不存在,則手工建立此文件。在Win32系統(tǒng)下,無法直接建立.htaccess 文件,則可以從其他系統(tǒng)中拷貝一份,也可以點擊這里下載我做的一個,解壓縮后即可使用。編輯并修改.htaccess文件,添加以下內(nèi)容 :
復(fù)制代碼 代碼如下:
# 將 RewriteEngine 模式打開
RewriteEngine On
# 修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
RewriteBase /discuz
# Rewrite 系統(tǒng)規(guī)則請勿修改
RewriteRule ^archiver/([a-z0-9\-]+\.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 ^profile-(username|uid)-(.+)\.html$ viewpro.php?$1=$2
添加內(nèi)容時,請遵照上面的提示,修改論壇所在的路徑,然后保存。將.htaccess文件上傳到論壇所在的目錄中。進入論壇系統(tǒng)設(shè)置,根據(jù)需要開啟URL靜態(tài)化功能。
-=======================================================
注意下面必須得
復(fù)制代碼 代碼如下:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
DocumentRoot "E:\aaa\wwwroot"
ServerName *
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.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 ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>
=======================
復(fù)制代碼 代碼如下:
NameVirtualHost 124.129.183.146
<VirtualHost bbs.jb51.net>
ServerName bbs.jb51.net
DocumentRoot D:/WebSite/phpbbs
<Directory "D:/WebSite/phpbbs">
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.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 ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^ss-xs/([0-9]+)/spacelist(.*)$ /index.php?$1/action_spacelist$2
RewriteRule ^ss-xs/([0-9]+)/viewspace_(.+)$ /index.php?$1/action_viewspace_itemid_$2
RewriteRule ^ss-xs/([0-9]+)/viewbbs_(.+)$ /index.php?$1/action_viewbbs_tid_$2
RewriteRule ^ss-xs/([0-9]+)/(.*)$ /index.php?$1/$2
RewriteRule ^ss-xs/([0-9]+)$ /index.php?$1
RewriteRule ^ss-xs/action_(.+)$ /index.php?action_$1
RewriteRule ^ss-xs/category_(.+)$ /index.php?action_category_catid_$1
RewriteRule ^ss-xs/itemlist_(.+)$ /index.php?action_itemlist_catid_$1
RewriteRule ^ss-xs/viewnews_(.+)$ /index.php?action_viewnews_itemid_$1
RewriteRule ^ss-xs/viewthread_(.+)$ /index.php?action_viewthread_tid_$1
RewriteRule ^ss-xs/index([.a-zA-Z0-9]*)$ /index.php
</IfModule>
</VirtualHost>
相關(guān)文章
Linux系統(tǒng)中kill命令殺死進程常用小技巧分享
這篇文章主要介紹了Linux系統(tǒng)中kill命令殺死進程常用小技巧,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06Linux動態(tài)啟用/禁用超線程技術(shù)的方法詳解
這篇文章主要給大家介紹了關(guān)于Linux動態(tài)啟用/禁用超線程技術(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Linux系統(tǒng)具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07linux創(chuàng)建用戶,添加及修改shell方式
這篇文章主要介紹了linux創(chuàng)建用戶,添加及修改shell方式。具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04如何在Linux環(huán)境為用戶添加sudo權(quán)限
這篇文章主要介紹了如何在Linux環(huán)境為用戶添加sudo權(quán)限,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09apache啟動報 shmget() failed: Invalid argument的解決方法
在apache啟動時報錯:“shmget() failed: Invalid argument”,如何解決呢?這里簡單分享下,方便需要的朋友2013-06-06