URL rewrite in tomcat web.xml

北慕城南 提交于 2019-12-11 05:06:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!