IIS7.5+WebConfig實現頁面偽靜態和301重定向
使用URLRewriter組件在windows 2003 +iis 6.0下配置偽靜態的文章網絡上一大堆。但在iis7.0或iis 7.5 環境下配置的網站基本上沒有講解的,就算有也是一些無用的代碼段,今天好不容易配置成功了,發個日記共享一下經驗。
文檔下載:http://files.cnblogs.com/files/dunitian/IIS7.5_WebConfig%E5%AE%9E%E7%8E%B0%E9%A1%B5%E9%9D%A2%E4%BC%AA%E9%9D%99%E6%80%81%E5%92%8C301%E9%87%8D%E5%AE%9A%E5%90%91.zip
- 先下載URLRewriter組件(點)
2.在網站項目中添加URLRewriter程序集的引用


3.配置webconfig文件
(1)在<configuration>與</configSections>節點中間設置:
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />

(2) 在<httpHandlers>與</httpHandlers>節點中間設置:
<add name="shtml" verb="*" path="*.shtml" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add name="html" verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />

(3) 在<httpModules>與</httpModules>節點中間設置:
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>

(4)規則配置的語法:
在<configuration>與</configuration>之間加入<RewriterConfig></RewriterConfig>節點。
在<RewriterConfig>與</RewriterConfig>之間加入規則:
<!--URLRewriter詳細配置規則部分開始-->
<RewriterConfig>
<Rules>
<!--偽靜態配置開始-->
<!--定義偽靜態第一條規則資料下載詳細頁-->
<RewriterRule>
<LookFor>^(.*)/Downloadshow/([0-9]+)\.shtml$</LookFor>
<SendTo>$1/Downloadshow/$2</SendTo>
</RewriterRule>
<!--定義偽靜態第二條規則學校課程詳細頁-->
<RewriterRule>
<LookFor>^(.*)/s-courseDetail/([0-9]+)\.shtml$</LookFor>
<SendTo>$1/schoolsite/courseDetail/$2</SendTo>
</RewriterRule>
<!--定義301重定向第一條規則資料下載詳細頁-->
<RewriterRule>
<LookFor>^(.*)/downdetail-([0-9]+)\.html$</LookFor>
<SendTo>$1/_301Deal/DownDetail/$2</SendTo>
</RewriterRule>
<!--定義301重定向第二條規則學校菜單列表頁-->
<RewriterRule>
<LookFor>^(.*)/xuexiao-(\w+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-\.html$</LookFor>
<SendTo>$1/_301Deal/SchoolList/$2-$3-$4-$5-$6-$7</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<!--URLRewriter詳細配置規則部分結束-->

~~~收工~~~
