如何创建仅传递请求路径的规则 - urlrewritefilter

时间:2014-11-03 01:12:03

标签: java tomcat proxy tuckey-urlrewrite-filter

由于我们在页面中使用ajax,因此我们需要提供来自Ajax Prerender服务的搜索机器人请求。

为此,我创建了一条规则来修改抓取请求。 <OUR_DOMAIN>/stocks?_escaped_fragment_=已转换为http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f/stocks

我使用了以下规则:

<rule>
        <name>escaped_fragment</name>
        <!--<condition type="request-filename" operator="notfile"/>-->
        <condition type="query-string" operator="equal">.*escaped_fragment.*</condition>
        <from>(.*)$</from>
        <to type="proxy" last="true" qsappend="true">http://www.MY_SEO_SERVER.com/TOKEN_e291b9f78$1</to>
    </rule>

问题是它生成了错误的网址:http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f/stockshttp://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f

很想获得有关如何正确构建规则的建议。

我正在使用urlrewritefilter - 4.0.3

日志:

DEBUG|http-apr-8080-exec-2|o.t.w.f.u.u.ServerNameMatcher | looking for hostname match on current server name localhost
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.UrlRewriteFilter    | checking for status path on /stocks
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.UrlRewriter| processing request for /stocks
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.RuleBase   | escaped_fragment (rule 0) run called with /stocks
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.RuleBase   | matched "from"
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.Condition  | evaluating "_escaped_fragment_=" against .*escaped_fragment.*
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.RuleBase   | conditions match
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.s.MatcherReplacer   | found 1
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.s.MatcherReplacer   | replaced sb is http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f/stocks
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.s.MatcherReplacer   | found 1
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.s.MatcherReplacer   | replaced sb is http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f
DEBUG|http-apr-8080-exec-2|o.t.w.f.u.RuleExecutionOutput | needs to be 
proxied from http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f/stockshttp://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f
DEBUG|http-apr-8080-exec-2|o.t.w.f.urlrewrite.UrlRewriter| rule is last
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | execute, 
target is http://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f/stockshttp://www.MY_SEO_SERVER.com/MY_TOKEN_e291b9f
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | response commit state: false
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | checking url
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | seting up the host configuration
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | config is HostConfiguration[host=http://www.MY_SEO_SERVER.com]
 INFO|http-apr-8080-exec-2|o.t.w.f.u.RequestProxy        | setting proxy request parameter:connection, value: keep-alive

1 个答案:

答案 0 :(得分:0)

它似乎是UrlRewriteFilter的一个错误。添加&#34; /&#34;到了并做了伎俩。

这是最终规则

<rule>
        <name>escaped_fragment</name>
        <!--<condition type="request-filename" operator="notfile"/>-->
        <condition type="query-string" operator="equal">.*escaped_fragment.*</condition>
        <from>^/(.*)$</from>
        <to type="proxy" last="true" qsappend="true">http://www.MY_SEO_SERVER.com/TOKEN_e291b9f78/$1</to>
    </rule>