用Intelligencia.UrlRewriter实现url重写

108 篇文章 2 订阅

Intelligencia.UrlRewriter 是一个比较老的url重写类,url重写的目的不外乎那几种,更友好的url,或利于seo,这是不多讲。

点击下载Intelligencia.UrlRewriter 点击下载urlrewriter

使用步骤

1 添加引用后,先配置web.config

<?xml version="1.0"?>
<configuration>
<!--urlrewriter 配置-->
  <configSections>
    <section name="rewriter"
             requirePermission="false"
             type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
  </configSections>
  <appSettings>
    <add key="AppCode" value="1508866"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
    </compilation>
    <httpRuntime/>
 
  </system.web>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE"/>
      </customHeaders>
    </httpProtocol>
<!--urlrewriter 配置-->
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRewriter" />
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
    </modules>
  </system.webServer>
<!--urlrewriter 重写规则配置-->
  <rewriter>
    <rewrite url="~/h5/products/(.+)" to="~/h5/products.aspx?id=$1"/>
    <rewrite url="~/h5/book/(.+)/(.+)" to="~/h5/cbook.aspx?tid=$1id=$2" />
    <!--<rewrite url="~/h5/book/(.+)/(.+)" to="~/h5/cbook.aspx?tid=$1id=$2" processing="stop"/>-->
  </rewriter>
</configuration>

2 根据配置的规则,在项目中添加 products.aspx, cbook.aspx页面处理,基本的重写就实现了

有关更多的实现url重写可以看网友的这篇 ASP.NET 整理比较全的URL重写解决方案

 

--- end ---

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值