あなたはHAProxy 1.5を使用していて、アップこれが機能するかどうかについて、あなた
単一ドメイン:(汚いけど作品)
# match non www requests:
acl has_www hdr_beg(host) -i www.
# add a header that says we need to redirect these type of requests (will explain later)
http-request add-header X-Host-Redirect yes unless has_www
# rule to identify newly added headers
acl www_redirect hdr_cnt(X-Host-Redirect) eq 1
# where the magic happens (insert www. in front of all marked requests)
reqirep ^Host:\ (.*)$ Host:\ www.\1 if www_redirect
# now hostname contains 'www.' so we can redirect to the same url
redirect scheme http if www_redirect
:
acl has_www hdr_beg(host) -i www
redirect prefix http://www.example.com code 301 unless has_www
複数のドメイン新しいヘッダーを追加する理由は、HAProxy 1.5以降では、ACLがbei各基準で評価された。新しいヘッダーなしでこれを実行しようとすると、次のようになります。
#catch all domains that begin with 'www.'
acl has_www hdr_beg(host) -i www.
#insert www. in front of all non www requests
reqirep ^Host:\ (.*)$ Host:\ www.\1 unless has_www
#now hostname contains 'www.' so when the next rule gets interpreted it does not match then fails
#redirect to new url
redirect code 301 prefix/if has_www
これが役立ちます。私はHAProxy 1.5に5個の異なるドメインでこれをテストしてみた、それがうまく働いたとパスとクエリパラメータ保存リダイレクトするHAProxy 1.6のリダイレクト
あなたはどのバージョンのHAProxyを使用していますか? –