iis 中的僞靜態設置

 

1、將下載的 IIS Rewrite 組件解壓,放到適當的目錄(如 C:Rewrite)下。


2、在“IIS管理器”裏選擇網站,右鍵,屬性。


3、選擇“ISAPI”,點擊“添加”。


4、填入篩選器名稱,如“rewrite”。


5、可執行文件下方點擊“瀏覽”,選擇剛纔解壓的Rewrite組件位置,Rewrite.dll。


6、確認選擇正確後,點擊“確定”。


7、點擊“確定”,完成篩選器添加。


8、重啓IIS。



9、重啓IIS後,再次選擇站點,右鍵,屬性,看到如下所示向上的綠箭頭,說明 IIS Rewrite 成功添加並運行。


IIS Rewrite 規則設置

解壓後的 IIS Rewrite 組件目錄(如 C:Rewrite)中,有一個 httpd.ini 文件,將相應規則寫入到這個文件中即可。

1. 安裝重寫插件Rewrite.dll

如果你的 IIS 服務器加載過 Rewrite.dll 則可以不用下載。

Rewrite.dll文件:百度搜索關鍵字:Rewrite.dll 下載

加載 Rewrite.dll

在 IIS 的 Isapi 上添加篩選器

篩選器名稱爲:re

可執行文件選擇 Rewrite.dll 就可以了!

2. 配置 httpd.ini
打開你的httpd.ini,找到

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
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

以上是 Discuz!官方提供的配置代碼,注意正則格式。

3. 應用
比如,將read.php?bl_id=123&bu_id=456 僞靜態成 /html/123/456.html

可以這樣寫:

RewriteRule ^(.*)/html/([0-9]+)/([0-9]+).html$ $1/read.php?bl_id=$2&bu_id=$3

要使你的IIS服務器支持僞靜態重寫,按以下步驟來:

1. 安裝重寫插件Rewrite.dll

如果你的 IIS 服務器加載過 Rewrite.dll 則可以不用下載。

加載 Rewrite.dll

在 IIS 的 Isapi 上添加篩選器

篩選器名稱爲:re

可執行文件選擇 Rewrite.dll 就可以了!

2. 配置 httpd.ini
打開你的httpd.ini,找到

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
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


以上是 Discuz!官方提供的配置代碼,注意正則格式。

3. 應用
比如,將read.php?bl_id=123&bu_id=456 僞靜態成 /html/123/456.html

可以這樣寫:

RewriteRule ^(.*)/html/([0-9]+)/([0-9]+).html$ $1/read.php?bl_id=$2&bu_id=$3

再例:

123.php?id=123
123/id/123
RewriteRule ^123/id/([0-9][0-9][0-9])/$ /123.php?id=$1
or
RewriteRule ^123/id/([0-9]+)$ /123.php?id=$1


PW的規則:[ISAPI_Rewrite]
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)/simple/([a-z0-9_]+.html)$ $1/simple/index.php?$2

個人備註:

這裏的$1, $2, $3就是前一個表達式的匹配值

比如:

^(.*)/simple/([a-z0-9_]+.html)$ $1/simple/index.php?$2

中對應的顏色對應相應的值! 

 

Windows2003 IIS6/7僞靜態組件下載/安裝/配置(附僞靜態規則) 
  http://www.xp-sem.com/windows2003-iis6-iis7-url-rewrite/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章