在haproxy中设置cookie时如何不重定向?

Ope*_*aus 5 load-balancing mobile-devices redirect haproxy cookie

在我的网站上,我使用Haproxy负载均衡器将使用移动设备的用户重定向到移动网站。我对此有一些抱怨,并希望为用户提供一个返回“经典”门户的链接。由于并非所有子页面都以移动格式提供,因此我必须首先选择内容是否可用。

    acl path_root path /
    acl path_mobile path_beg /faq
    acl site_classic hdr_sub(cookie) CLASSIC=
    acl ua_smartphone hdr_reg(User-Agent) -i iphone ipod android bada
    redirect location http://s.tld if path_root ua_smartphone !site_classic
    redirect prefix http://s.tld if path_mobile ua_smartphone !site_classic
Run Code Online (Sandbox Code Playgroud)

如果用户进入顶级目录,只需重定向该位置。如果“移动”用户点击移动格式中可用的内容,则重定向包括完整路径。到目前为止,这一切都很好。

现在,当他/她单击移动版本中设置名为“CLASSIC”的 cookie 的链接时,我不想再重定向用户。

cookie 设置正确并且工作正常。如果我写以下重定向工作:

    acl site_classic hdr_sub(cookie) CLASSIC=
    redirect location http://s.tld if site_classic
Run Code Online (Sandbox Code Playgroud)

我还尝试了所有可以想到的检查 cookie 的方法,例如 CLASSIC=1 CLASSIC=true CLASSIC=portal 等,并在代码中

    acl site_classic hdr_sub(cookie) CLASSIC
    acl site_classic hdr_sub(cookie) CLASSIC=
    acl site_classic hdr_sub(cookie) CLASSIC=1
    acl site_classic hdr_sub(cookie) CLASSIC=true
    acl site_classic hdr_sub(cookie) CLASSIC=portal
Run Code Online (Sandbox Code Playgroud)

为什么它不起作用?

感谢您的帮助!

小智 0

我认为您不能多次使用相同的 ACL 名称,请尝试使用如下内容:

acl site_classic1 hdr_sub(cookie) CLASSIC
acl site_classic2 hdr_sub(cookie) CLASSIC=
acl site_classic3 hdr_sub(cookie) CLASSIC=1
acl site_classic4 hdr_sub(cookie) CLASSIC=true
acl site_classic5 hdr_sub(cookie) CLASSIC=portal

redirect location http://s.tld if site_classic1 or site_classic2 or site_classic3 or site_classic4 or site_classic5
Run Code Online (Sandbox Code Playgroud)