使用Intelligencia.UrlRewriter.DLL实现URL重写

1、添加Intelligencia.UrlRewriter.dll的引用

2、在web.config中设置三个地方:

     (1)在<configSections></configSections>节中加上<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />;

     (2)在<httpModules></httpModules>节中加上<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>;

     (3)在<configuration></configuration>节中添加<rewriter>    <rewrite url="~/(.+).html$" to="~/ViewNews.aspx?ID=$1" />  </rewriter>

 

注:~/(.+).html$是要重写的匹配正则,呈现给用户,实际地址是~/ViewNews.aspx?ID=$1,即把$1的值给括号的地方,比如实际地址ViewNews.aspx?ID=123,用户看到的地址是123.html。

以上如果重写为aspx页面,不需要配置IIS,如果重写为HTML页面,需要在IIS中配置通配符应用程序映射,如下图

posted @ 2009-03-01 21:04  JasonChou  阅读(3867)  评论(4编辑  收藏  举报