0

我有多个 RewriteCond 序列,我希望作为 IF/ELSE 模式工作。即纯文本,它看起来像这样

IF there is no Cookie THEN redirect to other host, 
ELSE, Serve the requested file

我有 RewriteCond 如下:

RewriteEngine on         
#If there is no cookie in the request fwd the request to ABC
    RewriteCond %{HTTP_COOKIE} !^.*Cookie.*$ [NC]
    RewriteRule ^(.*)$ http://abc.xyz.com:<port>$1 [P,L]
    ProxyPreserveHost On
    ProxyPass / http://abc.xyz.com/
    ProxyPassReverse / http://abc.xyz.com:<port>/
#else serve the file    
    RewriteCond %{HTTP:Cookie} ^xxxx-xxxx-xxxx-credentials-a=.*$ [NC]
    RewriteRule /([^/]*\.nff).*$ /srv/samba/Assets/$1 [NC,L]

但是,Else RewriteCond 不起作用,即使请求标头有 Cookie,它仍然会被重定向。我有什么遗漏吗?

4

1 回答 1

0

Ok..I found solution after reading apache docs. Below is the modified code

    RewriteCond %{HTTP:Cookie} ^xxxx-xxxx-xxxx-credentials-a=.*$ [NC]
    RewriteRule /([^/]*\.nff).*$ /srv/samba/Assets/$1 [NC,L]    

#If there is no cookie in request fwd the request to    abc                  
    RewriteRule ^(.*)$ http://abc.xyz.com:<port>$1 [P]
    ProxyPreserveHost On
    ProxyPass / http://abc.xyz.com/
    ProxyPassReverse / http://abc.xya.com:<port>/

As there is just IF then Else, then no need to use 'Skip' all I need to do is stop looping. So I added [L] in the first rule and removed other rewritecond.

于 2013-10-31T17:37:24.530 回答