在tomcat web.xml中重写URL [英] URL rewrite in tomcat web.xml

查看:146
本文介绍了在tomcat web.xml中重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动将对 http://example.com 的请求重定向到

I would like to automatically redirect requests for http://example.com to http://example.com/SomePage

我可以使用以下规则使用Apache做到这一点:

I am able to do that with Apache with the following rule:

RewriteRule ^/$ /SomePage [R]

但是,我的某些服务器不能在Apache之上运行,而只能在Tomcat之上.如何在web.xml中实现等效功能? SomePage是一个struts2动作.

However, some of my servers do not run on top of Apache, just Tomcat. How do I implement the equivalent in web.xml? SomePage is a struts2 action.

推荐答案

如果您是单独使用Tomcat,而不是通过modrewrite与Apache一起使用,则最好的方法是安装重写过滤器并从web.xml中引用它.我过去使用的一种过滤器是来自tuckey.org(http://www.tuckey.org/)的UrlRewriteFilter.

If you are using Tomcat alone instead of with Apache with modrewrite, the best approach is to install a rewrite filter and reference it from your web.xml. One filter I have used in the past is UrlRewriteFilter from tuckey.org (http://www.tuckey.org/).

它在Google代码上,位于 http://code.google.com/p/urlrewritefilter/source/browse/trunk/src/test-web/WEB-INF/urlrewrite.xml .

It is on Google Code at http://code.google.com/p/urlrewritefilter/source/browse/trunk/src/test-web/WEB-INF/urlrewrite.xml.

上次更新是在2010年10月,但我确实记得它运行良好.配置文件是XMLish,而不是您在modrewrite中使用的很好的衬板.

Last update was in October 2010, but I do remember it working just fine. Config files are XMLish, not the nice one liners that you use in modrewrite.

这篇关于在tomcat web.xml中重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆