復制代碼 代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--第一步注冊url重寫模塊放到webconfig的最上部-->
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<!--第二步添加重寫規則-->
<RewriterConfig>
<!--先制定全部重寫規則內容-->
<Rules>
<!--制定每個單獨頁面的規則-->
<RewriterRule>
<!--原始請求地址-->
<SendTo><![CDATA[~/news.aspx?id=$1&pid=$2]]></SendTo>
<!--重寫後的地址-->
<LookFor>~/news/(.[0-9]*)/(.[\d]*)\.html</LookFor>
</RewriterRule>
<RewriterRule>
<!--原始請求地址-->
<SendTo><![CDATA[~/product.aspx?pid=$1]]></SendTo>
<!--重寫後的地址-->
<LookFor>~/product/(.[\d]*)\.zangdalei</LookFor>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<compilation debug="false" targetFramework="4.0">
<!--第四部url重寫防止真實的頁面也被重寫如果網站中真實存在頁面,需要添加編譯指令不編譯真實的html文件-->
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
<!--第三部url重寫 將用戶的請求頁面交給相應的處理程序,注意請求的後綴名格式-->
<httpHandlers>
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.zangdalei" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="aspnethtml" path="*.html" verb="GET,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
<add name="aspnetzangdalei" path="*.zangdalei" verb="GET,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
</handlers>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
<add value="default.html" />
</files>
</defaultDocument>
</system.webServer>
</configuration>