URLRewriteFIlter, How to remove the context/folder name?

邮差的信 提交于 2019-12-14 01:58:57

问题


Link to my previous question, I want to rewrite the http://www.demo.com/context/user.do?action=home to http://www.demo.com, and was advised to try URLRewriteFilter.

The following code

   <rule>
        <from>^/$</from>    
        <to type="redirect">%{context-path}/user.do?action=home</to>    
   </rule>

does not removes the context name, that is I still need to enter from http://www.demo.com/context/

Given all the example in the official site is based on top of the context, is the RewriteFilter really the right tool to solve the initial problem?


回答1:


You need to deploy the webapp on the context root instead. Either rename the WAR to ROOT.war (and remove the default /ROOT folder in Tomcat's webapps, if any) so that Tomcat will autodeploy it on root, or edit the <Context> element of the webapp's context.xml to specify path="" instead of path="/context".

The rewrite filter runs at webapp level only, not at Tomcat level, so trying to use it to change the webapp's context path (which is by itself to be configured at Tomcat level) makes no sense.

See also:

  • Tomcat6 -> how to put a project into the root folder?


来源:https://stackoverflow.com/questions/8556407/urlrewritefilter-how-to-remove-the-context-folder-name

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