码迷,mamicode.com
首页 > Web开发 > 详细

用URLRewriter重写url

时间:2015-04-30 19:56:23      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

用url重新一般都是使用URLRewriter库,基本上都是一些配置,在webconfig中

首先配置configuration节点

<configSections>
            <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter" />
    </configSections>

<system.webServer>节点下添加

<system.webServer>
<handlers>
   <add name="Rewriter" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" 
requireAccess
="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" /> </handlers> </system.webServer>

 

接下来就是写规则了。在webconfig的configuration内部的最底部添加RewriterConfig节点,并写规则

 1 <!--url重写规则-->
 2     <RewriterConfig>
 3         <Rules>
 4             <!--圈子-->
 5             <RewriterRule>
 6                 <LookFor>~/(.*)/list/(.*)</LookFor>
 7                 <SendTo>~/group/circlelist.aspx?name=$1&amp;keyword=$2</SendTo>
 8             </RewriterRule>
 9             <RewriterRule>
10                 <LookFor>~/group/(.*)</LookFor>
11                 <SendTo>~/group/circle.aspx?name=$1</SendTo>
12             </RewriterRule>
13             <!--快速索引 字母-->
14             <RewriterRule>
15                 <LookFor>~/i/(.*)_(.*).html</LookFor>
16                 <SendTo>~/stock/indexing.aspx?i=$1&amp;page=$2</SendTo>
17             </RewriterRule>
18             <!--快速索引 型号列表-->
19             <!--<RewriterRule>
20                 <LookFor>~/(.*[^online,^askbuy,^ic,^services]).html</LookFor>
21                 <SendTo>~/stock/searchStock.aspx?keyword=$1</SendTo>
22             </RewriterRule>-->
23             <!--在线展会-->
24             <RewriterRule>
25                 <LookFor>~/online.html</LookFor>
26                 <SendTo>~/stock/onlineindex.aspx</SendTo>
27             </RewriterRule>
28             <!--求购专区-->
29             <RewriterRule>
30                 <LookFor>~/askbuy.html</LookFor>
31                 <SendTo>~/seller/askbuylist.aspx</SendTo>
32             </RewriterRule>
33             <!--IC圈子-->
34             <RewriterRule>
35                 <LookFor>~/ic.html</LookFor>
36                 <SendTo>~/member/icCircle.aspx</SendTo>
37             </RewriterRule>
38             <!--龙维商软服务-->
39             <RewriterRule>
40                 <LookFor>~/services.html</LookFor>
41                 <SendTo>~/stock/services.aspx</SendTo>
42             </RewriterRule>
43             <!--快速索引 型号列表-->
44             <RewriterRule>
45                 <LookFor>~/(.*).html</LookFor>
46                 <SendTo>~/stock/searchStock.aspx?keyword=$1</SendTo>
47             </RewriterRule>
48         </Rules>
49     </RewriterConfig>

 

这些基本上已经好了。但发布到iis上还需配置一些东西。即处理映射

选择你发布的网站。选择"处理程序映射"

 

技术分享

然后:

技术分享

选择路径:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

保存即可。

 

用URLRewriter重写url

标签:

原文地址:http://www.cnblogs.com/nsky/p/4469574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!