java - 带有 tomcat 的 UrlRewrite 过滤器

标签 java tomcat url-rewriting

我在我的 java 项目上使用 org.tuuckey.web.filters.urlrewrite.UrlRewriteFilter。它工作正常。我的问题是它更改了现有的 url。

示例我需要将 mainurl/news/cricket 重定向到 mainurl/news.jsp/id=2

myurlrewriter.xml

<rule>
    <note>
        The rule means that requests to /test/status/ will be redirected to /rewrite-status
        the url will be rewritten.
    </note>
    <from>/news/cricket</from>
    <to type="redirect">%{context-path}/news.jsp/id=2</to>
</rule>

它将整个 url 重定向到 news.jsp/id=2 但我不想更改 url,只更改内容,这可能吗?有人知道怎么做。

非常感谢您的帮助。

谢谢, VKS.

最佳答案

然后不要使用重定向。它将发送 302,这意味着它告诉浏览器页面已移动。只需丢失 type="redirect":

<rule>
    <note>
        The rule means that requests to /test/status/ will be redirected to /rewrite-status
        the url will be rewritten.
    </note>
    <from>/news/cricket</from>
    <to>/news.jsp/id=2</to>
</rule>

关于java - 带有 tomcat 的 UrlRewrite 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9563884/

相关文章:

url-rewriting - 我如何知道安装了哪个版本的 IIS7 URL 重写模块

java - Spring LDAP : error code 4 - Sizelimit Exceeded - when setting countLimit to 1

java - 添加这些匿名类的最紧凑/高效/可维护的方式

java - 工厂方法 'dataSource' 在启动时抛出异常

tomcat - httpclient:通过 https 将 HttpResponse 复制到 HttpServletResponse

tomcat - 使用 tomcat6 在 apache2 上重写规则

url-rewriting - ASP.NET Core 1.1 Url 重写 - www 到非 www

java - Stripes ActionBean 事件总是解析为默认事件

javascript - 网站和移动应用程序的登录 API 应该相同还是不同?

tomcat - 如何从自签名证书的 keystore 中导出私钥