2012-11-20 3 views
0

나는 이상한 문제에 직면하고 있습니다. 하나의 규칙 (마지막 규칙)을 실행하면 포워딩 전에 404 오류가 발생하는 경우가 있습니다.URLRewriteFilter 규칙을 URL에 2 번 덧붙입니다.

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 

답변

0

몇 가지 성공 사례를 통해 해결책을 찾았습니다. AllRemainingRequests의 "from"구성 요소가 문제가됩니다. 다음 정의를 AllRemainingRequests에 적용하면 정상적으로 작동합니다.

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

만 변화 "/"

입니다
관련 문제