URLRewriteFIlter, How to remove the context/folder

2019-07-18 22:24发布

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条回答
干净又极端
2楼-- · 2019-07-18 23:12

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:

查看更多
登录 后发表回答