URLRewriteFIlter,如何删除上下文/文件夹名称? [英] URLRewriteFIlter, How to remove the context/folder name?

查看:60
本文介绍了URLRewriteFIlter,如何删除上下文/文件夹名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接到我之前的问题,我想将 http://www.demo.com/context/user.do?action=home 重写为 http://www.demo.com,并被建议试试 URLRewriteFilter.

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.

以下代码

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

不删除上下文名称,即我仍然需要从http://www.demo.com/context/

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

鉴于官方网站中的所有示例都是基于上下文的,RewriteFilter 真的是解决最初问题的正确工具吗?

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?

推荐答案

您需要改为在上下文根上部署 Web 应用程序.Either 将 WAR 重命名为 ROOT.war(并删除 Tomcat 的 webapps 中默认的 /ROOT 文件夹,如果有的话),以便 Tomcat 自动部署它在根目录下,编辑 web 应用程序的 context.xml 元素以指定 path="" 而不是 path="/context".

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".

重写过滤器仅在 webapp 级别运行,而不是在 Tomcat 级别运行,因此尝试使用它来更改 webapp 的上下文路径(它本身要在 Tomcat 级别配置)是没有意义的.

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.

这篇关于URLRewriteFIlter,如何删除上下文/文件夹名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆