2010-12-22

URL Rewriting, 使用網址轉換模組, 於 IIS 7 的設定

使用網址轉換模組, 於 IIS 7 的設定

Using the URL Rewrite Module
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Creating Rewrite Rules for the URL Rewrite Module
http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

快速入門

下載 URL Rewrite module
( URL Rewrite http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691 )
x86 version of the URL Rewrite module http://go.microsoft.com/?linkid=9722533
x64 version of the URL Rewrite module http://go.microsoft.com/?linkid=9722532
下載之後直接安裝好即可

範例: http://localhost/urlx/Default/123/test/
轉換至 http://localhost/urlx/Default.aspx?id=123&title=test

請先準備好你的 default.aspx
開啟 IIS 7 管理員, 點選至你要設定的虛擬目錄,
點兩下 URL Rewrite 項目, Add Rule(s)...
現在要來新增一個轉換網址的規則, 選擇 Blank rule, 確定
Name 請輸入這個轉換規則的名稱, 例如: Default.aspx
Pattern 請輸入轉換規則的定義, 以 regular expression 表示,
例: ^Default/([0-9]+)/([_0-9a-z-]+)
Rewrite ULR 請輸入轉換之後的網址,
此例中我們是要轉換給 default.aspx 處理,
請輸入: Default.aspx?ID={R:1}&title={R:2}
這個轉換規則的意思即是,
把網址 http://localhost/urlx/ 之後,
符合 Default/123/test 這種樣子的網址,
轉換為 Default.aspx?id=123&title=test
給 Default.aspx 這個 asp.net 網頁處理

沒有留言:

熱門文章