Apache偽靜態(tài)html(URL Rewrite)設(shè)置法
一 打開 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>
- <ifmodule mod_rewrite.c>
- RewriteEngine On
- RewriteRule /news/top2007,(d+).html$ /news/readmore.php?id=$1
- </ifmodule>
四 保存httpd.conf并重啟apache。
Apache Web Server(獨(dú)立主機(jī)用戶)
首先確定您使用的 Apache 版本,及是否加載了 mod_rewrite 模塊。
Apache 1.x 的用戶請(qǐng)檢查 conf/httpd.conf 中是否存在如下兩段代碼:
LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c
Apache 2.x 的用戶請(qǐng)檢查 conf/httpd.conf 中是否存在如下一段代碼:
LoadModule rewrite_module modules/mod_rewrite.so
如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代碼。此時(shí)請(qǐng)務(wù)必注意,如果網(wǎng)站使用通過(guò)虛擬主機(jī)來(lái)定義,請(qǐng)務(wù)必加到虛擬主機(jī)配置,即 <VirtualHost>中去,如果加在虛擬主機(jī)配置外部將可能無(wú)法使用。改好后然后將 Apache 重啟。
- <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>
如果沒(méi)有安裝 mod_rewrite,您可以重新編譯 Apache,并在原有 configure 的內(nèi)容中加入 --enable-rewrite=shared,然后再在 Apache 配置文件中加入上述代碼即可。
Apache Web Server(虛擬主機(jī)用戶)
在開始以下設(shè)置之前,請(qǐng)首先咨詢您的空間服務(wù)商,空間是否支持 Rewrite 以及是否支持對(duì)站點(diǎn)目錄中 .htaccess 的文件解析,否則即便按照下面的方法設(shè)置好了,也無(wú)法使用。
檢查播客所在目錄中是否存在 .htaccess 文件,如果不存在,請(qǐng)手工建立此文件。Win32系統(tǒng)下,無(wú)法直接建立 .htaccess 文件,您可以從其他系統(tǒng)中拷貝一份,或者在discuz.net 技術(shù)支持欄目中下載此文件。編輯并修改 .htaccess 文件,添加以下內(nèi)容:
- #將 RewriteEngine 模式打開 RewriteEngine On
- # 修改以下語(yǔ)句中的 /supev 為你的播客目錄地址,如果程序放在根目錄中,請(qǐng)將 /supev 修改為 /
- ?RewriteBase /supev
- # Rewrite 系統(tǒng)規(guī)則請(qǐng)勿修改 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=$1
- <VirtualHost *:80>
- DocumentRoot /home/www_php168
- ServerName www.111cn.cn
- <IfModule mod_rewrite.c>
- RewriteEngine On
- RewriteRule ^(.*)/list-([0-9]+)-([0-9]+).htm$ $1/list.php?fid=$2&page=$3
- RewriteRule ^(.*)/bencandy-([0-9]+)-([0-9]+)-([0-9]+).htm$ $1/bencandy.php?
- fid=$2&id=$3&page=$4
- </IfModule>
- </VirtualHost>
新聞熱點(diǎn)
疑難解答
圖片精選