gpt4 book ai didi

java - Tomcat URL 重写过滤器工作不正常

转载 作者:行者123 更新时间:2023-11-28 22:28:07 25 4
gpt4 key购买 nike

我需要像这样转发一个 url

http://localhost:8080/doc/service?type=testLogin&exectype=userShow&moreparms

到:

http://localhost:8080/xyz/service?type=testLogin&exectype=userShow&moreparms

系统运行 tomcat 8.0.28 并且已经加载了 URLRewriteFilter ( http://www.tuckey.org/urlrewrite/ ),但是没有使用我在 googlecode.com 的 urlrewritefilter-site 上提到的需要放入的以下特定代码webapps/doc/WEB-INF/web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

然后我将以下规则添加到与 web.xml 相同目录中的 urlrewrite.xml:

<urlrewrite>
<rule>
<from>^/doc/(.*)$</from>
<to type="redirect">/xyz/$1</to>
</rule>

<outbound-rule>
</outbound-rule>
<urlrewrite>

我在尝试访问类似的内容时收到 404 错误消息

http://localhost:8080/doc/service?type=testLogin&exectype=userShow&moreparms

如果我尝试,我也会收到 404 错误

http://localhost:8080/doc/status

示例规则如下:

<urlrewrite>
<rule>
<from>/doc/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>
<outbound-rule>
<from>/rewrite-status</from>
<to>/doc/status/</to>
</outbound-rule>
<urlrewrite>

但是

http://localhost:8080/doc/rewrite-status

有效。

我的错在哪里?

附言:我使用的是 Win10 专业版和 urlrewritefilter-4.0.3

最佳答案

<rule>
<from>^/doc/(.*)$</from>
<to type="redirect">/xyz/$1</to>
</rule>

<from><to>在你的统治下应该交换。尝试类似的东西:

<rule match-type="wildcard">
<from>^/xyz/**</from>
<to>/doc/$1</to>
</rule>

UrlRewriteFilter - Manual 中所述,以上将把对/xyz/** 的请求转发到/doc/**

出站规则类似<rule>但处理传递给 response.encodeURL() 的 URL .

关于java - Tomcat URL 重写过滤器工作不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33912523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com