urlRewrite

阅读更多
熟悉apache的朋友都应该对apache的urlwrite的强大功能很熟悉,呵呵,今天的主角不是apache,而是urlRewriteFilter。 一个基于过滤器的java实现。
Based on the popular and very useful mod_rewrite for apache, 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.
urlrewrite的好处就不多说了,这里简单说一下配置。
安装:
1. 下载lib文件解压缩到web目录下,目前的版本是1.2。下载地址:http://tuckey.org/urlrewrite/dist/urlrewritefilter-1.2.zip
2.   编辑 WEB-INF/web.xml 加入下面的配置(filter-mapping自定义)
    
        UrlRewriteFilter
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
   

   
        UrlRewriteFilter
        /*
   

3.   在WEB-INF目录中创建规则配置文件urlrewrite.xml.
4. 重启应用环境.
简单吧。具体来看几个地方
web.xml::
    
        UrlRewriteFilter
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
       
            confReloadCheckInterval
            60
       

       
            logLevel
            DEBUG
       

       
            statusEnabled
            true
       

       
            statusPath
            /status
       

   

1) confReloadCheckInterval : 设置检查,加载配置文件的时间间隔,0或空表示永远不检查重新加载
2) logLevel: 日志记录level
3) statusEnabled:
4)statusPath:
urlrewrite.xml:跳转规则的配置文件,具体请参考UrlRewriteFilter DTD (Document Type Definition).
规则定义采用正则表达式(Perl5 style),具体参考Jakarta ORO's的说明文档
例子:
   
        /products/([0-9]+)
        /products/index.jsp?product_id=$1
   


http://localhost/example/products/1 将会更具规则重定向到 http://localhost/example/products/index.jsp?product_id=1

你可能感兴趣的:(urlrewrite)