Forum Moderators: phranque

Message Too Old, No Replies

redirecting http to https - through an haproxy

         

lbenfey

1:48 am on Nov 11, 2010 (gmt 0)

10+ Year Member



Heya guys,

I have run into a frustrating situation with what I expected to be a completely simple operation, and I was wondering if anyone out there might have some ideas.

We are using a fairly bogstandard Haproxy LB and Apache server setups in our ec2 deployments. I am trying to do something that seems like it should be very simple -- That is: Redirect all requests that come in to a specific http URL (http://example.com/dir1/dir2/signin) to the https version of the same url (https://example.com/dir1/dir2/singnin).

I have a fair amount of experience with mod_rewrite, and I have tried to do this ordinarily very simple operation in every way that I can think of in the App server's .vhost file. However, no matter what I do, the operation ends up looping. Essentially, the first rewrite is successful, and [......] DOES correctly redirect to [...,...] but then it just loops and loops, repeatedly redirecting to https:// again and again, ignoring any attempt I make to limit the rule by RewriteConds that specify only to run the rule on non-HTTPS/non-Port 443, etc.

For instance:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/dir1/dir2/signin$ "https://%{HTTP_HOST}/dir1/dir2/signin" [R=301,L]

or:
RewriteCond %{HTTPS} !=on
RewriteRule ^/dir1/dir2/signin$ "https://example.com/dir1/dir2/signin" [R=301,L]

(these are not the only things I have tried, not by a long shot, but just wanted to give you an illustrative example)


Have you any idea why this problem is happening and how we can get this simple operation to actually work? We're not trying to do anything complicated or weird, and it seems like other people must have encountered the same issue, no?

I am pretty sure that it is the configuration of haproxy that is causing this to happen. Apache on the LB is configured to just take everything that comes into it on port 80 or port 443 and shove it through to haproxy (127.0.0.1:85). Apache on the LB has two separate .vhost files, one for connections on port 80, and one for connections on port 443.

Thanks, any information you can provide would be very much appreciated,

- Luke

lbenfey

5:28 pm on Nov 11, 2010 (gmt 0)

10+ Year Member



Just to add some more information:

So. If I don't have ANY redirect rules in place, then I can explicitly go to either http:// or https:// just fine. However, once I put the redirect rule into place, it breaks. As an experiment, I also tried redirecting the entire site to https to see if that would work... but, no, I still encounter the same problem. That is to say, when I go to http://example.com then, according to firebug, it makes the first redirect fine (to [example.com),...] but then at that point it just loops.

g1smd

10:15 pm on Nov 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What does Live HTTP Headers for Firefox show?