URL重寫規則(Rewrite Rule),也就是隻要將寫好的httpd.ini放在站點根目錄,就能使用了。php
安裝說明:下載後能夠解壓出 ISAPI_Rewrite.dll ,httpd.ini 這兩個文件放到某個文件夾下面,而後在 IIS 站點屬性的 ISAPI 中加載 ISAPI_Rewrite.dll 就能夠了, httpd.ini 是配置文件裏面有例子。若是加載不成功的話 請給 ISAPI_Rewrite.dll 安全屬性爲徹底。html
二、在「IIS管理器」裏選擇網站,右鍵,屬性。api
三、選擇「ISAPI」,點擊「添加」。安全
四、填入篩選器名稱,如「rewrite」。服務器
五、可執行文件下方點擊「瀏覽」,選擇剛纔解壓的Rewrite組件位置,Rewrite.dll。ide
六、確認選擇正確後,點擊「肯定」。
七、點擊「肯定」,完成篩選器添加。網站
八、重啓IIS。ui
九、重啓IIS後,再次選擇站點,右鍵,屬性,看到以下所示向上的綠箭頭,說明 IIS Rewrite 成功添加並運行。spa
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