UrlRewriteFilter是一个用于改写URL的Web过滤器,类似于Apache的mod_rewrite。适用于任何Web应用服务器(如Resin,Orion,Tomcat等)。其典型应用就把动态URL静态化,便于搜索引擎爬虫抓取你的动态网页。
UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as Resin, Orion or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.
使用方法1:
1、下载http://tuckey.org/urlrewrite/#download目前版本是1.2,解压缩后将文件考到相应的web-inf/lib和web-inf下,。
2、配置web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
根据自己的需要,将相应目录下的url转给UrlRewriteFilter来处理。
3、配置urlwrite规则文件WEB-INF/urlrewrite.xml
http://www.nihaoblog.com/content.jsp?id=1&contentid=404
静态化为:
http://www.nihaoblog.com/content/1_404.html
配置如下:
<rule>
<from>/content/([0-9]+)_([0-9]+).html</from>
<to>/content.jsp?id=&contentid=</to>
</rule>
使用方法2:
1、下载urlrewritefilter-1.1.zip (about 500kb) ,解压缩后将文件考到相应的web-inf/lib和web-inf下。
2、配置web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
根据自己的需要,将相应目录下的url转给UrlRewriteFilter来处理。
3、配置urlwrite规则文件WEB-INF/urlrewrite.xml
添加自己的urlwrite规则,如将
http://localhost/aaa/bbb.jsp?id=99&name=abc
表现为:
http://localhost/aaa/bbb/99_abc.html
配置如下:
<rule>
<from>/aaa/bbb/([0-9]+)_([a-z]+).html</from>
<to>/../aaa/bbb.jsp?id=&name=</to>
</rule>
UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as Resin, Orion or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.
使用方法1:
1、下载http://tuckey.org/urlrewrite/#download目前版本是1.2,解压缩后将文件考到相应的web-inf/lib和web-inf下,。
2、配置web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
根据自己的需要,将相应目录下的url转给UrlRewriteFilter来处理。
3、配置urlwrite规则文件WEB-INF/urlrewrite.xml
http://www.nihaoblog.com/content.jsp?id=1&contentid=404
静态化为:
http://www.nihaoblog.com/content/1_404.html
配置如下:
<rule>
<from>/content/([0-9]+)_([0-9]+).html</from>
<to>/content.jsp?id=&contentid=</to>
</rule>
使用方法2:
1、下载urlrewritefilter-1.1.zip (about 500kb) ,解压缩后将文件考到相应的web-inf/lib和web-inf下。
2、配置web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
根据自己的需要,将相应目录下的url转给UrlRewriteFilter来处理。
3、配置urlwrite规则文件WEB-INF/urlrewrite.xml
添加自己的urlwrite规则,如将
http://localhost/aaa/bbb.jsp?id=99&name=abc
表现为:
http://localhost/aaa/bbb/99_abc.html
配置如下:
<rule>
<from>/aaa/bbb/([0-9]+)_([a-z]+).html</from>
<to>/../aaa/bbb.jsp?id=&name=</to>
</rule>