1 地址目录为:http://www.test.com/a/b/c/index.jsp ,因为访问的路径文件夹太长,我需要把这个地址重写一下,在地址栏上显示为一个简短的地址,最终我访问的浏览器地址栏效果为http://www.test.com/a_b_c_index.jsp ,2 如果可以的话难度再大点,先改成http://bbs.test.com/a/b/c 完了后再改成http://bbs.test.com/a_b_c_index.jsp(结论)也就是想访问地址栏为http://www.test.com/a/b/c/index.jsp 而最终地址栏显示为 http://bbs.test.com/a_b_c_index.jsp 。 麻烦大家帮我写个这样的重写规则。

解决方案 »

  1.   

    请问:a_b_c_index.jsp是要真实存在,还是虚拟存在?
      

  2.   


    虚拟的,
    (结论)也就是想访问地址栏为http://www.test.com/a/b/c/index.jsp(真实路径文件) 而最终地址栏显示为 http://bbs.test.com/a_b_c_index.jsp(虚拟显示路径文件) 。 麻烦大家帮我写个这样的重写规则。
      

  3.   

    STRUTS里面不就可以直接访问ACTION名吗。
      

  4.   

    这个不是只是单一替换么,都不需要pattern
    在rewrite规则中替换请求中包含的a/b/c/index.jsp
    为a_b_c_index.jsp
      

  5.   

    个人认为:这个其实很简单。就一个filter就可以。先用Redirect重定向到a_b_c_index.jsp。再用forward到a/b/c/index.jsp就可以。
    代码基本如下:
      String url = ((HttpServletRequest)request).getRequestURI();
    if(url.equals("/a/b/c/index.jsp.jsp")){
    ((HttpServletResponse)response).sendRedirect("/a_b_c_index.jsp");
    }
    if(url.equals("/a_b_c_index.jsp")){
    request.getRequestDispatcher("/a/b/c/index.jsp.jsp").forward(request, response);
    }
    else{
    chain.doFilter(request, response);
    }
      

  6.   


    <rule>
      <from>http://^(\w+).test.com/(\w+)_(\w+)_(\w+)_index.jsp$</from>
      <to>http://$1.test.com/$2/$3/$4/index.jsp</to>
    </rule>urlRewriter配置下就可以了