我依次有多个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,它仍然会被重定向。 有什么我想念的吗?
答案 0 :(得分:0)
好的..我在阅读apache docs后找到了解决方案。以下是修改后的代码
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>/
因为只有IF然后Else,所以我不需要使用'Skip'所有我需要做的就是停止循环。所以我在第一条规则中添加了[L]并删除了其他重写。