Intelligencia.UrlRewriter使用说明(转)

    技术2023-03-29  17

    1.Server2000/2003/XP操作系统下IIS的配置:

    官网:http://urlrewriter.net/index.php/support/installation

     

    2.UrlRewriter.net(入门篇)(进阶篇)(高级篇)代码示例:

    下载:/Files/Fred_Xu/UrlRewriter.NET.rar

     

    3.Intelligencia.UrlRewriter在IIS7、7.5中的配置方法:

          在vista、win7、server2008中,iis的版本是v7+,IIS6重写配置在IIS7中重写无效解决方案由于IIS6只能在请求被分配到Asp.Net引擎后才能发生重写操作,IIS7可以在IIS请求管道的任何地方执行一个HttpModule, 而且IIS7对于文件或文件夹的访问权限得重新设置.

          如果是IIS7.0/7.5的运行环境,添加该配置

     

      < system.webServer >   < modules >   <!-- 您的自定义IIS重写模块操作 -->   < add  name ="UrlRewriter"  type ="Intelligencia.UrlRewriter.RewriterHttpModule" />   </ modules >   </ system.webServer >

     

     问题即可解决!

    摘引自ScottGu的Blog:

    <? xmlversion="1.0"encoding="UTF-8" ?>   < configuration >   < configSections >   < sectionname ="rewriter"  requirePermission ="false"  type ="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,Intelligencia.UrlRewriter" />   </ configSections >   < system.web >   < httpModules >   < addname ="UrlRewriter" type ="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" />   </ httpModules >   </ system.web >   < system.webServer >   < modulesrunAllManagedModulesForAllRequests ="true" >   < addname ="UrlRewriter" type ="Intelligencia.UrlRewriter.RewriterHttpModule" />   </ modules >   < validationvalidateIntegratedModeConfiguration ="false" />   </ system.webServer >   < rewriter >   < rewriteurl ="~/products/(.+)" to ="~/products.aspx?category=$1" />   </ rewriter >   </ configuration >

     参考博文:http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx 【推荐】

            http://aspalliance.com/1234_TipTrick_Url_Rewriting_with_ASPNET.3

          http://www.improve.dk/blog/2006/12/11/making-url-rewriting-on-iis7-work-like-iis6

    4.重写HTML的规则示例:

    (1)

    注意:

    当使用通配符映射或者使用ASP.NET处理所有HTTP请求的时候,IIS的默认文档机制也就失去了该有的作用,以下代码就是用来重新实现默认文档的方法:

    <rewrite url="^(.*)/(/?.+)?$" to="$1/default.aspx$2" />注意:使用“processing="restart"”的时候将会导致重写引擎从头开始执行所有的重写规则,此时应当注重包含“/default.aspx”字符串的处理。

    如果你需要同时支持多个默认文档,那么以上代码需要修改为:

    <if url="^(.*)/(/?.+)?$">

     <rewrite exists="$1/default.aspx" to="$1/default.aspx$2" />

     <rewrite exists="$1/index.aspx" to="$1/index.aspx$2" />

     <rewrite exists="$1/index.html" to="$1/index.html$2" />

    </if>编辑以上规则代码的时候,尤其要注意确认文件是否存在。

    此外,在使用通配符映射或者使用ASP.NET处理所有HTTP请求的时候,你会发现.gif、.css等文件无法正常访问,这是因为此时对这些文件类型的处理都被ASP.NET所拦截。修正方法如下:

    <rewrite

     url="^(/.+(/.gif|/.png|/.jpg|/.ico|/.css|/.js)(/?.+)?)$"

     to="$1" processing="stop" />两个比较特殊的正则表达式字符是“^”和“$”(不是必须的),“^”代表URL的开头,“$”代表URL的结尾。使用这两个符号可以使您更加精确的控制重写动作,以确保程序所匹配的URL正是您想处理的。

    “~/”表示当前网站应用程序运行所在的虚拟根目录,当您把网站应用程序安装于虚拟目录(或者非根目录)的时候,这尤其有用,而无须重新编写任何代码来替换您的虚拟根路径。

    模式匹配在处理查询字串(QueryStrings)的时候尤其有用,这可以让您的URL去掉类似于“?id=3”的代码段,这非常有用,可以让你轻松的实现伪静态。

    下面列出两个我们认为非常有特色的重写规则:

    (1) 当目标URL不包含自定义查询字串的时候:

    <rewrite url="^~/mypage(/?.+)?$" to="~/default.aspx$1" />此时“$1”匹配的是(/?.+)?,也就是所有的查询字串。

    (2) 当目标URL包含自定义查询字串的时候:

    <rewrite url="^~/mypage(/?(.+))?$"

     to="~/default.aspx?page=mypage&$2" />注意此时需要使用“&amp;”来代替“&”,这是XML文档语法的需要。

     

    本文来自博客,转载请标明出处:http://blog.csdn.net/bl_song/archive/2009/11/03/4761343.aspx

    (2)

    < rewriter >      < rewrite  url ="~/default.html$"  to ="~/default.aspx"  processing ="stop"   />      < rewrtie  url ="^~/(/d+)/(/d+).html"  to ="~/Default.aspx?id=$1&amp;artcleid=$2"   /> //多个参数     < rewrite  url ="~/news_([0-9]+).html$"  to ="~/Article/ArticleShow.aspx?id=$1"  processing ="stop"   />      < rewrite  url ="~/Result_([0-9]+).aspx$"  to ="~/Job/Company/Result.aspx?cid=$1"  processing ="stop"   />      < rewrite  url ="~/company_([0-9]+).html$"  to ="~/Company/$1/index.html"  processing ="stop"   />      < rewrite  url ="~/Resume/([0-9]+)_([0-9]+).html$"  to ="~/Resume/$1/Resume_$2.html"  processing ="stop"   />      < rewrite  url ="~/([0-9]+)_([0-9]+).html$"  to ="~/company/$1/job_$2.html"  processing ="stop"   />      < rewrite  url ="~/job_([0-9]+).html$"  to ="~/company/$1/jobs_$1.html"  processing ="stop"   />      < rewrite  url ="~/news_l([0-9]+)_1.html$"  to ="~/company/$1/$1_news.html"  processing ="stop"   />      < rewrite  url ="~/news_([0-9]+)v([0-9]+).html$"  to ="~/company/$1/n_$2.html"  processing ="stop"   />      < rewrite  url ="~/contact_([0-9]+).html$"  to ="~/company/$1/contact.html"  processing ="stop"   />      < rewrite  url ="~/a_(.+)_(.+).aspx$"  to ="~/a.aspx?id=$1&amp;id1=$2"  processing ="stop"   /> //多个参数  </ rewriter >  

     

    5.博客园资源整理:

    JeffreyZhao 赵劼的博文:

    重提URL Rewrite(1):IIS与ASP.NET

    重提URL Rewrite(2):使用已有组件进行URL Rewrite

    重提URL Rewrite(3):在URL Rewrite后保持PostBack地址 //这篇文章对我帮助最大了,在实际项目中是一定要用到的。

    重提URL Rewrite(4):不同级别URL Rewrite的一些细节与特点

     

    6.Intelligencia.UrlRewriter和fck editor冲突问题:

      在IIS7/7.5环境中,,建议使用集成模式,不要使用Classic模式,否则UrlRewriter和fck editor会有冲突,造成fck editor的页面无法执行URL。

     

     

     

    转:http://dev.tot.name/dotnet/html/20100519/20100519103834.htm

    最新回复(0)