我想使用urlrewritefilter去实现url rewrite。可是配置总是无法实现,各位大大帮我看看怎么回事第一步:我在我的程序文件夹中的web\web-inf中建立一个文件urlrewrite.xml 然后在里面添加:
<urlrewrite>
    <rule>
        <note>
            The rule means that requests to /test/status/ will be redirected to /rewrite-status
            the url will be rewritten.
        </note>
        <from>/test/status/</from>
        <to type="redirect">%{context-path}/rewrite-status</to>
    </rule>    <outbound-rule>
        <note>
            The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
            the url /rewrite-status will be rewritten to /test/status/.            The above rule and this outbound-rule means that end users should never see the
            url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
            in your pages.
        </note>
        <from>/rewrite-status</from>
        <to>/test/status/</to>
    </outbound-rule>第二步:在程序文件夹中的web/web-inf中建立一个文件夹lib。然后拷贝jar文件urlrewrite-3.0.4.jar到这个目录下第三步:建了一个测试的jsp文件index.jsp。这个文件内容是:<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Hello World!</h2>
        <a href="/test/status/">test</a>
    </body>
</html>然后重启tomcat。不知道为什么怎么也无法实现url rewrite。在显示的页面上链接“test”的地址还是:http://localhost:8084/test/status/我很急啊,希望各位大大赐教啊,求你了!!!

解决方案 »

  1.   

    对不起,上面忘了一步:在程序文件夹/web/web-inf/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>
      

  2.   

    <outbound-rule>
    ...
             <from>/rewrite-status </from>
             <to>/test/status/ </to>
         </outbound-rule> 
    你这设的有问题吧?
      

  3.   

    UrlRewrite 对IIS 服务器和Apache服务器有不同的设置. 两种配置方法不同. 请广大用户千万注意.Apache服务器设置: 您需要在网站根目录创建 .htaccess 文件.编写规则.IIS 服务器设置: 您需要在网站根目录创建 httpd.ini 的配置文件, 编写规则.由于 IIS下的httpd.ini和 Apache的.htaccess 文件 是两种完全不同的配置方式.两个不能互换使用. 编写URLReWrite 需要专业的技术人员.如何对IIS服务器的网站 进行UrlRewrite的设置?注意 使用URlRewrite 不能开启 网站自定义 404错误,否则 UrlRewrite将无法正常工作具体的到:
    http://www.webwoo.net/bc/bencandy-11-29911-1.htm
      

  4.   

    举例: 应该为:  <from>(.*).html</from>  <to>/myweb/$1.jsp</to>
      

  5.   

    从你的配置上看不到什么问题,刚才我按照你的配置做了一个实例也没有问题。不过我用的是2.6的包,从官网的changelog来看没有什么配置上大的改动。我把我的测试用例传到csdn资源上了。你用我的用例测试一下。看看是否是环境的问题。Ps.现在csdn有问题。我自己上传成功但是获取不到地址。一会过来发地址。
      

  6.   

    刚才又下了下3.0.4的包试了下。成功~地址是http://download.csdn.net/source/409661你测试下试试~~~
      

  7.   

    十分感谢Pizzame的热心。我试试看看,好用了,就给你加分!
      

  8.   

    而你的 "redirect"  是转发的.
    如:  <rule>
             <from>/login.htm</from>
             <to type="redirect">http://localhost:8080/yourproject/</to>
         </rule> 
    明白了?
      

  9.   

    不是很明白!对不起,我是新手。呵呵我试过type="forward" 还有type=“redirect”,但都不好用。
      

  10.   

    哈哈,我楼上引用错了,应该是9楼。sorry
      

  11.   

    你给我的包我试了,不好意思还是不行。你给的包里有个index.jsp,我把她稍微改一下,以便与测试:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h2>Hello World!</h2>
            
            <a href="/test/status/">test</a>
        </body>
    </html>你给我的urlrewrite.xml中包含两个rule:<urlrewrite>    <rule>
            <from>/test/status/ </from> 
            <to type="redirect">%{context-path}/index.jsp </to>
         </rule>
        
        <outbound-rule>
             <from>/index.jsp</from>
             <to>/test/status/ </to> 
        </outbound-rule>
        
    </urlrewrite>我就在index.jsp中加了一个连接“test”,看看是否可以rewrite,可结果还是http://localhost:8084/test/status/。
    该怎么办啊,烦死了。
      

  12.   

    对了,我用的是netbeans 6.1版本,我没有eclipse。我在编译是得到两个警告:Warning: WEB-INF\lib\urlrewrite-2.6.0.jar modified in the future.Warning: lib\urlrewrite-2.6.0.jar modified in the future.不知和这个有没有关系?