第一步:在網站項目漲添加URLRewriter程序集的引用和FormRewriterControlAdapter程序集引用。
注:如果項目中有分頁,那么需要添加“FormRewriterControlAdapter”程序集引用,否則不需要添加該引用。
下載地址:http://www.net.cn/service/ziliao/cpsc/200906/3842.html(萬網/幫助中心(M享主機UrlRewrite組件和使用手冊))
第二步:配置webconfig文件:
注意事項:1、參數用()括起來,使用 $1 來獲得參數。2、多個參數的時候使用&分割。
1。在<configuration>與</configuration>節點中間加入如下配置:
<configSections> <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> </configSections>
2。 在<system.web>與</system.web> 之間加入
<httpHandlers> <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> </httpHandlers>
或者
<system.web> <httpModules> <add type=”URLRewriter.ModuleRewriter, URLRewriter” name=”ModuleRewriter”/> </httpModules> </system.web>
3。配置偽靜態的語法:在<configuration>與</configuration>之間加入<RewriterConfig> </RewriterConfig>節點。
在 <RewriterConfig>與</RewriterConfig>之間加入偽靜態規則:
<Rules> <!–定義偽靜態第一條規則開始–> <RewriterRule> <LookFor>~/xxxx/view(.[\d]*)\.html</LookFor> <SendTo>~/xxxx/view.aspx?id=$1</SendTo> </RewriterRule>
<!–定義偽靜態第一條規則結束–> <!–定義偽靜態第二條規則開始–> <RewriterRule> <LookFor>~/yyyy/(.[\d]*)/view.html</LookFor> <SendTo>~/yyyy/view.aspx?id=$1</SendTo> </RewriterRule>
例子如:
<RewriterConfig> <Rules> <!--官網--> <RewriterRule> <LookFor>~/web/new/type-(.[0-9]*)\.html</LookFor> <SendTo>~/web/new.aspx?id=$1</SendTo> </RewriterRule> <RewriterRule> <LookFor>/index.html</LookFor> <SendTo>/index.aspx</SendTo> </RewriterRule> <RewriterRule> <LookFor>/aboutus/aboutusContent-(.*).html</LookFor> <SendTo>/aboutus/aboutusContent.aspx?pageurl=$1</SendTo> </RewriterRule> <RewriterRule> <LookFor>/shop/GiftList-(.*)-(.*).html</LookFor> <SendTo>/shop/GiftList.aspx?nav=$1&price=$2</SendTo> </RewriterRule> <RewriterRule> <LookFor>/shop/list-(.*)-(.*)-(.*).html</LookFor> <SendTo>/shop/list.aspx?nav=$1&licno=$2&orderby=$3</SendTo> </RewriterRule> <RewriterRule> <LookFor>/shop/list-(.*)-(.*)-(.*)-(.*).html</LookFor> <SendTo>/shop/list.aspx?nav=$1&licno=$2&orderby=$3&price=$4</SendTo> </RewriterRule> </Rules> </RewriterConfig>
或者
<RewriterConfig> <rewriter> <rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" /> <rewrite url="~/lmh$" to="~/Users.aspx?user=lmh" processing="stop" /> <rewrite url="~/tags/(.+)" to="~/tag/tagcloud.aspx?tag=$1" processing="stop"/> <rewrite url="^~/mypage(\?.+)?$" to="~/index.htm$1" processing="stop" /> <rewrite url="~/article-([^-]+)-([^-]+)-([^-]+).html" to="~/testurl/article.asp?id=$1&sid=$2&page=$3" processing="stop"/> <rewrite url="^(.*)/(\?.+)?$" to="$1/index.htm$2?" /> </rewritr> </RewriterConfig>
url是可以使用正則表達式的。比如上面的例子:
規則一:當發現文件類型為 .gif, .png,.jpg, .ico, .pdf, .css or .js時,停止rewrite
規則二:就是將/lmh重寫到/Users.aspx?user=lmh,$在正則表達式中表示是串的結束,也就是說/lmhe是不會被重寫到to后的地址的,如果把$去掉則可以
規則三:將tags/xxx重寫為tag/tagcloud.aspx?Tag=xxx
規則四:當用戶輸入錯誤象mypagexxx形式的地址時,轉到網站默認頁面
規則五:設置用戶網站的默認頁面為index.htm
新添asp規則:將article.asp?id=13&sid=10&page=2通過偽靜態轉換成article-10-13-2.html格式來訪問頁面
第三步:配置IIS6.0
1、右鍵點擊 要設置網站的網站
2、屬性 ——》主目錄 ——》配置——》
3、如右側窗口,找到 .aspx 擴展名——》編輯——》復制 可執行文件的路徑——》關閉
4、點擊 添加——》粘貼 剛復制的 可執行文件路徑
5、擴展名填寫 .html (如果是 .htm 或者 任意你想要的擴展都可以 前提是以后的應用程序擴展列表里邊沒有該擴展)
6、不選中 確認文件是否存在
7、確定