三:UrlRewriter.NET重写数字化和多关键字URL地址
为了能够重写不存在文件夹的请求,需要将IIS按照第一篇"IIS配置"所讲进行配置。如果使用IIS 7,需要编辑项目的Web.config文件,添加如下所示的system.webServer条目
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests=“false”>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule"/>
</modules>
</system.webServer>
修改Web.config中<rewriter>单元,添加如下重写规则:
<rewriter url="^/Products/C([0-9]+)/P([0-9]+).html$" to="/Product.aspx?CategoryID=$1&ProductID=$2" processing="stop"/>
<rewriter url="^/Products/C([0-9+).html$" to="/Product.aspx?ProductID=$1" processing="stop"/>
如果测试成功,说明UrlRewriter.NET地址重写可以工作了!
PS:在所有的URL地址重写中,正则表达式都显得非常的重要,所有请关注正则表达式。