我有几个领域是我的主要领域的变化。 我想将它们全部redirect到我的主域,忽略协议(http / https)和子域(www./beta。)。 有没有办法做到这一点在HAProxyconfiguration?
我正在想着类似的东西
redirect prefix https://*.domainA.com code 301 if { hdr(host) -i *.domainB.com } redirect prefix https://*.domainA.com code 301 if { hdr(host) -i *.domainC.org }
将*.example.orgredirect到https://*.example.com ,如果存在,则保留子域,path和查询string(为了便于阅读,添加了换行符)…
http-request redirect location https://%[hdr(host),lower,regsub(\.example\.org$,.example.com,)]%[capture.req.uri] code 301 if { hdr_end(host) -i .example.org }
取到传入的主机头,转换为小写,然后做一个正则expression式replace.example.org锚定到最后,改为.example.com ,然后追加捕获的请求的URI,代码301,如果Host头结束在.example.org ,不区分大小写。
testing…
$ curl -v http://longcat.example.org/test?cat=1 * Connected to longcat.example.org (127.0.0.1) port 80 (#0) > GET /test?cat=1 HTTP/1.1 > User-Agent: curl/7.35.0 > Host: longcat.example.org > Accept: */* > < HTTP/1.1 301 Moved Permanently < Content-length: 0 < Location: https://longcat.example.com/test?cat=1 < Connection: close
用混合大小写主机头testing…
$ curl -v http://TACGNOL.eXaMpLe.ORG/ohai?cat=2 * Connected to TACGNOL.eXaMpLe.ORG (127.0.0.1) port 80 (#0) > GET /ohai?cat=2 HTTP/1.1 > User-Agent: curl/7.35.0 > Host: TACGNOL.eXaMpLe.ORG > Accept: */* > < HTTP/1.1 301 Moved Permanently < Content-length: 0 < Location: https://tacgnol.example.com/ohai?cat=2 < Connection: close
该解决scheme依赖于HAProxy 1.6中首次引入的function。
对每对域重复相应的编辑操作。