UrlRewriteFilter 学习笔记
1、简介 ?
??? UrlRewriteFilter是一个用于改写URL的Web过滤器,类似于Apache的mod_rewrite。适用于任何Web应用服务器(如Resin,Orion,Tomcat等)。其典型应用就把动态URL静态化,便于搜索引擎爬虫抓取你的动态网页。
?其主页:http://tuckey.org/urlrewrite/
2、安装
??? 在其主页下载该包文件,把其jar 包放在lib 目录下,在web.xml 中添加下面内容
<Context docBase="forum" path="/forum" reloadable="true" crossContext="true"/>
<to>null</to>表示当这个规则匹配时,将不会有任何的反应。
to元素可以包含后引用(backreferences)和变量
Backreferences
比如:?%N
??? Provides access to the grouped parts (parentheses) of the pattern from the last matched Condition in the current rule. N must be less than 10 and greater than 0 (i.e. %1, %2, %3 etc).?
(上面不理解,未翻译)
变量
%{varName}
任何变量的 condition type 可以被用来作为varName。比如:%{port}将被翻译为80 ,%{year}将被翻译成2009等
函数
%{function:params}
函数可以用在set元素或者to元素中。
名称实例输入结果replace${replace:my cat is a blue cat:cat:dog}
my dog is a blue dogreplaceFirst${replace:my cat is a blue cat:cat:dog}
my cat is a blue dogescape${escape:a b c}
a+b+cunescape${unescape:a+b+c}
a b clower${lower:Hello World}
hello worldupper${upper:hello}
HELLOtrim${trim: abc def }
abc defset元素
如果rule 匹配的话,允许你设置一些变量。
参数取值描述typerequest、session、cookie、charset等设置域的类型name任何数在request、session、response-header、cookie,有特殊的作用
实例: