问题
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.
回答1:
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.
回答2:
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>
来源:https://stackoverflow.com/questions/6631600/url-rewrite-in-tomcat-web-xml