现在的位置: 首页 > 综合 > 正文

二:使用UrlRewriter.NET

2012年12月03日 ⁄ 综合 ⁄ 共 1111字 ⁄ 字号 评论关闭

  UrlRewriter.NET是一个开源的URL地址重写组件,它的重写实现在ASP.NET层次,而不是IIS层次。

  首先,我们需要下载UrlRewriter.NET的安装包,然后解压到本地。

  二、在vs中引用Intelligencia.UrlRewriter.dll.

  三、配置Web.config,已让UrlRewriter.NET能够从名为rewriter的配置节点读取配置:

  <?xml version=“1.0”?>

  <configuration>
   <configSections>
    <section name="rewriter" restartOnExternalChanges="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,Intelligencia.UrlRewriter"/>
   </configSections>

注意:configSetctions单元必须是configuration单元的第一个子单元。

  四、现在配置UrlRewriter HTTP模块,以允许UrlRewriter.NET截获到来的请求(并重写它们)

  <system.web>

  <httpModules>
     <add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" name="UrlRewriter"/>
   </httpModules>

  五、现在UrlRewriter.NET已经可以工作了,下面对/my-super-product.aspx的到来请求重写为/Product.aspx?ProductiD=123。在Web.config的<configuration>节中添加以下突出显示的配置单元:

  <configuration>

    <rewriter>

      <rewriter url="/my-super-product.aspx" to="/Product.aspx?ProductiD=123">

    </rewriter>

  ...

也许,看到这 很多人觉得不过瘾,在实际项目中不可能只有一个url地址需要重写,还有多个参数和不同参数的URL,下次再谈谈重写数字化和多关键字URL地址的方法。

 

参考:《Professinal Search Engine Optimization with ASP.NET:A Developer's Guide to SEO》

抱歉!评论已关闭.