HAProxy: Redirect Root Site Root to Subsite

haproxyredirect

I would like to redirect the root of my website to a subsite by default. Like

http://www.domain.com/ ---> http://www.domain.com/subsite

I have tried this, but this matches all the URLs anyway:

acl is_root path_beg -i /
acl is_domain hdr(host) -i www.domain.com

redirect code 301 location http://www.domain.com/subsite if is_domain is_root

Best Answer

nlu is almost there, but the is_root ACL is a little bit off.

Using path_beg will lead to any and all paths being matched, when really you only want to redirect requests with an empty path.

Try using acl is_root path -i / instead since it will only match when the path is ONLY /.

acl is_root path -i /
acl is_domain hdr(host) -i www.domain.com

redirect code 301 location http://www.domain.com/subsite if is_domain is_root
Related Topic