大网数据广告活动
服务器运维问答

how to redirect on the requested scheme (http or https)

· 52CE 我爱测

I'm redirecting to some domain based on an acl condition but I want the user to end up on either http or https depending on the scheme/protocol of their request. I've managed to do that with the 2 lines shown bellow, but I'd like…

问题原文

原帖链接 · cherouvim · CC BY-SA 3.0

I'm redirecting to some domain based on an acl condition but I want the user to end up on either http or https depending on the scheme/protocol of their request. I've managed to do that with the 2 lines shown bellow, but I'd like to convert them to just 1 line:

http-request redirect code 301 location http://www.example.com%[url] if acl_whatever !{ ssl_fc }
http-request redirect code 301 location https://www.example.com%[url] if acl_whatever { ssl_fc }

Ideally I'd like to redirect to something like %[scheme]://www.example.com%[url] but %[scheme] does not exist.

Is there a variable or function which can return http or https so I do not have to repeat the rule twice? Maybe by somehow setting a variable containing the scheme or maybe by using the value of %[ssl_fc] which is 0 or 1?

已采纳解答

原帖链接 · Tollef Fog Heen · CC BY-SA 3.0

You can do this using http-request set-var and %[var(name)]:

http-request set-var(req.scheme) str(https) if { ssl_fc }
http-request set-var(req.scheme) str(http) if ! { ssl_fc }
http-request redirect code 301 location %[var(req.scheme)]://www.example.com%[url] if acl_whatever

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。