2015-01-15 60 views
1

我是新手在正則表達式,所以請裸露在我身邊。我使用Tuckey URLRewrite,我需要它接受除了「/」或「\」一切規則正則表達式在Tuckey UrlRewrite

我已經寫了一個規則,但tuckey顯示無休止的異常,不加載頁面

<rule> 
     <from>^/post/([^/\n\\]+)/type/([a-z]+)$</from> 
     <to>/post/?slug=$1&amp;type=$2</to> 
    </rule> 

regexr我已經驗證了這個表達式「([^/\ n \] +)」會選擇除「/」或「\」之外的所有內容,但是我收到了異常。我錯過了什麼嗎?

這裏是例外:

at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281) 
    at org.tuckey.web.filters.urlrewrite.RuleBase.matchesBase(RuleBase.java:205) 
    at org.tuckey.web.filters.urlrewrite.NormalRule.matches(NormalRule.java:92) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRuleProcessing(RuleChain.java:83) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.process(RuleChain.java:137) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:144) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) 
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) 
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) 

。 。 繼續..

請指導。

+0

**除了「/」**和'^/post /([^/\ n \\] +)/ type /([a-z] +)$'是否相同? – anubhava 2015-01-15 17:38:01

+0

我沒有得到你在說什麼,但我已經更新了我的問題 – iConfused 2015-01-16 06:53:36

+0

當你有這個異常時,你輸入了什麼URL? – anubhava 2015-01-16 08:35:39

回答

3

OP有過這樣的規則:

<rule> 
<from>^/post</from> 
<to>/post/</to> 
</rule> 

<rule> 
<from>^/post/([^/]+)</from> 
<to>/post/?slug=$1</to> 
</rule> 

<rule> 
<from>^/post/([^/]+)/type/([a-z]+)$</from> 
<to>/post/?slug=$1&amp;type=$2</to> 
</rule> 

問題顯然是這裏的排序規則。由於第一種模式:^/post覆蓋任何以/post開頭並導致像^/post/([^/]+)/type/([a-z]+)$之類的模式被完全忽略的任何內容。

這些規則需要重新排序是這樣的:

<rule> 
<from>^/post/([^/]+)/type/([a-z]+)$</from> 
<to>/post/?slug=$1&amp;type=$2</to> 
</rule> 

<rule> 
<from>^/post/([^/]+)</from> 
<to>/post/?slug=$1</to> 
</rule> 

<rule> 
<from>^/post</from> 
<to>/post/</to> 
</rule> 

保持低於特定目標的人一般捕獲所有類型的規則。

+1

謝謝。這工作! – iConfused 2015-01-16 15:01:06

+0

不客氣,很高興它解決了。 – anubhava 2015-01-16 15:04:43

相關問題