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 。 麻烦大家帮我写个这样的重写规则。
虚拟的,
(结论)也就是想访问地址栏为http://www.test.com/a/b/c/index.jsp(真实路径文件) 而最终地址栏显示为 http://bbs.test.com/a_b_c_index.jsp(虚拟显示路径文件) 。 麻烦大家帮我写个这样的重写规则。
在rewrite规则中替换请求中包含的a/b/c/index.jsp
为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);
}
<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配置下就可以了