开发者

URL rewrite in tomcat web.xml

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

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

RewriteRule ^/$ /SomePage [R]

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.开发者_StackOverflow


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/).

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

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.


I would just use <welcome-file-list> in the web.xml. For example

<welcome-file-list>    
  <welcome-file>SomePage.html</welcome-file>
</welcome-file-list>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜