mod_rewrite规则未生效

时间:2016-01-26 07:29:52

标签: apache .htaccess mod-rewrite

我的app有以下apache配置,我想设置一个规则,当URL包含fname参数时,它应该重写为/v1/documents以及url中的所有Query参数。在所有其他情况下,它应该重写http://localhost:8003/v1/documents以及查询参数。请帮忙。

   ProxyRequests Off
    ProxyPreserveHost On

    Timeout 2400
    ProxyTimeout 2400
    ProxyBadHeader Ignore

    RewriteEngine ON
    # for old bugtrack style url compatibility
    RewriteRule ^/(.\d+)$ /goto/$1 [R]

    # to handle /v1/ routes containing uri in old bugtrack
    RewriteCond %{QUERY_STRING} uri=(other-document/.*)$
    RewriteRule ^/v1/documents http://localhost:9000/download.xqy?file=%1 [P]

    RewriteCond %{QUERY_STRING} bn=(.\d+)$
    RewriteRule ^/bug-details\.xqy$ /goto/%1? [R,L]

    ######################### 
    this rule is not taking effect, THE URL is going to proxypassmatch
    RewriteCond %{QUERY_STRING} !fname=
    RewriteRule ^/v1/documents /v1/documents [QSA,R,L] 
    ########################

    ProxyPassMatch /v1/.*$ http://localhost:8003
    ProxyPass / http://localhost:9050/ retry=1 acquire=3000 timeout=2400 Keepalive=On
    ProxyPassReverse / http://localhost:9050/

1 个答案:

答案 0 :(得分:1)

尝试:

# after : this rule is not taking effect, THE URL is going to proxypassmatch
RewriteCond %{QUERY_STRING} fname=
RewriteRule !^/?v1/documents/?$ /v1/documents [QSA,R,L]
RewriteRule ^/?v1/documents - [L]