以前的一篇关于UrlRewrite文章,UrlRewritingNet 完美实现 ASP.NET 2.0 中的URL重写(映射) .有一些园友留言对于无扩展名的UrlRewrite无法实现,如:http://www.xxx.com/Register,下面就把实现细节及注意事项说一下,还有问题的请下载源码.
(1)在2003系统下,按照下图在IIS中设置添加统配符,另外注意圈红的地方.
(2)在XP系统下,在扩展名影射中,扩展名:.*,处理程序aspnet_isapi(感谢提供思路).
2 站点中引入UrlRewrting.dll
3 Web.config配置修改如下:
<appSettings>
<add key="SiteUrls" value="~/SiteUrls.config"/>
</appSettings>
<httpModules>
<add name="MyHttpModule" type="UrlRewriting.MyHttpModule,UrlRewriting"/>
</httpModules>
<httpHandlers>
<add verb="*" type="UrlRewriting.Http404,UrlRewriting" path="404.aspx"/>
</httpHandlers>
4 SiteUrls.config如下:
Code
<?xml version="1.0" encoding="utf-8" ?>
<RewriterConfig>
<RewriterRule>
<LookFor>~/Register</LookFor>
<SendTo>~/Register.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Login</LookFor>
<SendTo>~/Login.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/EN/DownLoad/(\d{4,12})_(\d{2,8})/(\d{1,5})/Default\.aspx</LookFor>
<SendTo><![CDATA[~/EN_DownLoadIntro.aspx?&Catalog=$2&id=$3]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/BoardList_(\d{1,8})</LookFor>
<SendTo><![CDATA[~/BoardList.aspx?BigClassID=$1]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Board_(\d{1,8})</LookFor>
<SendTo><![CDATA[~/Board.aspx?SmallClassID=$1]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Topic_(\d{1,8})</LookFor>
<SendTo><![CDATA[~/Topic.aspx?ID=$1]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Post</LookFor>
<SendTo><![CDATA[~/Post.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Register</LookFor>
<SendTo><![CDATA[~/Register.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Login</LookFor>
<SendTo><![CDATA[~/Login.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Logout</LookFor>
<SendTo><![CDATA[~/Logout.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserInfo_([\w]+)</LookFor>
<SendTo><![CDATA[~/UserInfoDetail.aspx?UserID=$1]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserCenter</LookFor>
<SendTo><![CDATA[~/UserCenter.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserTopics</LookFor>
<SendTo><![CDATA[~/UserTopics.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserPosts</LookFor>
<SendTo><![CDATA[~/UserPosts.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserFavorates</LookFor>
<SendTo><![CDATA[~/UserFavorates.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserInMails</LookFor>
<SendTo><![CDATA[~/UserInMails.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserSendMail</LookFor>
<SendTo><![CDATA[~/UserSendMail.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/UserOutMails</LookFor>
<SendTo><![CDATA[~/UserOutMails.aspx]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/ffsu(.*)</LookFor>
<SendTo><![CDATA[~/PageParse.aspx?p=$1]]></SendTo>
</RewriterRule>
</RewriterConfig>
5 测试
下载