gpt4 book ai didi

tomcat - URLRewriteFilter 规则附加到 url 2 次

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

我遇到了一些奇怪的问题。执行一条规则(最后一条规则)是在转发前将 url 放入时间,这给了我 404 错误。

web.xml 内容

    <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>
<!-- FORWARD dispatcher will keep on parsing requests through rule until
atleast one rule is applied . It sometime may lead into infinite loop
-->
<!-- <dispatcher>FORWARD</dispatcher> -->
</filter-mapping>

我的规则

<rule>
<name>DepreatedUrls</name>
<from>(/my/url2|/my/url3)</from>
<set type="status">410</set>
<to last="true">%{context-path}/error/410.html</to>
</rule>

<rule>
<name>AllRemainingRequests</name>
<note>
This rule will block all other requests and return http error
404 ( not supported ) and custom error message .
</note>
<from>(.*)</from>
<set type="status">404</set>
<to last="true">/error/410.html</to>
</rule>

所有其他规则执行良好。每条规则都是最后一条规则 (last="true")。但是当执行最后一条规则时,它将请求转发到/error/410.html/error/410.html

为了简单起见,我删除了大部分规则定义。以下是调试日志

Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: AllRemainingRequests (rule 8) run called with /some-content
Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: matched "from"
Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.SetAttribute DEBUG: set Set status null 404 called
Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.SetAttribute DEBUG: setting status
Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.RuleExecutionOutput DEBUG: needs to be forwarded to /error/410.html/error/410.html
Nov 20, 2012 12:31:10 PM org.apache.catalina.core.ApplicationContext log
INFO: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: rule is last

最佳答案

经过一些尝试和尝试,我找到了解决方案。AllRemainingRequests 的“from”组件令人不安。当我为 AllRemainingRequests 放置以下定义时,它工作正常。

<rule>
<name>AllRemainingRequests</name>
<from>(/.*)</from>
<set type="status">404</set>
<to last="true">/error/410.html</to>
</rule>

唯一变化的是“/”

关于tomcat - URLRewriteFilter 规则附加到 url 2 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13473594/

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