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 ---