Haproxy exclude a url from https redirection

haproxy

I am beginner with haproxy and trying to do same basic redirection with haproxy

I have 2 sites

  1. www.test.com -> want to this to be redirected to https
  2. www.test.com/helpsub -> Should not redirect to https and remain on http

Is this possible ?

Best Regards,

W

Best Answer

Assuming you are using the 1.5 version of HAProxy.

To redirect to https can be done via the redirect scheme directive. This directive has an optional conditions list, so you could set up an ACL for this purpose.

For instance to set up an acl to match the /helpsub path, you could have:

acl helpsub path_beg /helpsub

And to then do the redirect to https for everything, except the helpsub (and of course only when the connection is not yet via ssl) you could have:

redirect scheme https if !{ ssl_fc } !helpsub

The ! sign means not matching, so basically this reads as:

redirect the request to the https scheme, if you are not on an ssl connection and the path does not start with /helpsub.

Reference.