IIS 原生不支持 URL Rewrite,需安裝第三方 ISAPI 組件(Helicon ISAPI_Rewrite 為主流選擇)。本文匯總 ShopEx 4.7/4.8、Discuz、ECShop、DVBBS、PHPWind、WordPress 等熱門程序在 IIS 下的偽靜態規則與部署步驟。
httpd.conf,語法兼容 Apache .htaccess,推薦用於 ShopEx 4.8、Discuz X、WordPress 等現代程序。下載:https://www.helicontech.com/download/isapi_rewrite/ISAPI_Rewrite3_0056_Lite.msihttpd.ini,語法較舊,適用 ShopEx 4.7 等老版本程序。下載:https://www.isapirewrite.com/download/isapi_rwl_x86_0072.msi關鍵限制:3.x 與 2.x 不能混用。同一 IIS 站點僅能加載一個版本。多站點共存時,若程序版本不一致,需在站點級單獨加載/卸載篩選器,避免規則衝突。
默認安裝至 C:\Program Files\Helicon\ISAPI_Rewrite3\,確保目錄授予 Users 與 Network Service 讀取權限。
httpd.conf# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.56
RewriteBase /
# 靜態文件直通
RewriteCond %{REQUEST_FILENAME} \.(html|htm|php|php2|php3|php4|php5|phtml|pwml|inc|asp|aspx|ascx|jsp|cfm|cfc|pl|cgi|shtml|shtm|phtm|xml)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32
# 保護配置文件
RewriteRule ^(.*)/archiver/((fid|tid)-[0-9]+\.html)\?*(.*)$ $1/archiver/index\.php\?$2&$4
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/forumdisplay\.php\?fid=$2&page=$3&$4
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/viewthread\.php\?tid=$2&extra=page\%3D$4&page=$3&$4
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html\?*(.*)$ $1/space\.php\?$2=$3&$4
RewriteRule ^(.*)/tag-(.+)\.html\?*(.*)$ $1/tag\.php\?name=$2&$3
站點屬性 → ISAPI 篩選器 → 添加:
ISAPI_Rewrite3C:\Program Files\Helicon\ISAPI_Rewrite3\ISAPI_Rewrite.dll重啟 IIS 生效(iisreset)。
httpd.ini 規則示例[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32
# 首頁
RewriteRule /index.html /index.php
RewriteRule /default.html /index.php
# 商品分類/列表/詳情
RewriteRule /catalog.html /index.php\?gOo=goods_category.dwt
RewriteRule /list.html /index.php\?gOo=goods_search_list.dwt
RewriteRule /list_([0-9]+).html /index.php\?gOo=goods_search_list.dwt&p=$1
RewriteRule /product/([0-9]+).html /index.php\?gOo=goods_details.dwt&goodsid=$1
RewriteRule /product_([0-9]+).html /index.php\?gOo=goods_details.dwt&goodsid=$1
# 文章/幫助/會員等
RewriteRule /article_([0-9]+).html /index.php\?gOo=help_details.dwt&articleid=$1
RewriteRule /member.html /index.php\?gOo=member_home.dwt
# ... 更多規則參考原文
Rewrite,指向 Rewrite.dll。若 IIS 同時運行 ShopEx、Discuz、PHPWind 等程序,全局加載單一 Rewrite 篩選器會導致規則互相干擾。解決方案:
URL Rewrite Module (web.config),實現站點級獨立配置偽靜態組件安裝需服務器管理員權限。虛擬主機用戶無法自行安裝,需確認主機商已預裝支持所用程序的 Rewrite 組件及規則。
文末提供多程序規則與組件打包下載(原文鏈接已失效),建議從官方渠道獲取最新版組件與官方推薦規則。