Hi Errol,
On Mon, Oct 07, 2013 at 06:13:16AM -0400, Errol Neal wrote:
> Hi all. I sent this earlier last week. Still having some trouble getting it
> to work.
> I'm just trying to redirect all requests to http://www.$domain.com.
> Based on some googling, here is what I have:
>
> acl host_www hdr_beg(host) -i www.
> reqirep ^Host:\ (.*)$ Host:\ www.\1 if !host_www
>
> Then I try to redirect..
>
> redirect code 301 prefix / if host_www
>
> But the above redirect line seems to generate a loop.
> Can anyone share any thoughts?
Yes, the problem is that the second request will match host_www
and cause the redirect as well. If you're doing that in your
frontend, I can suggest the following trick. Use a backend
dedicated to redirects and send the traffic there when you
see that the request lacks "www." :
frontend foo
bind :80
use_backend redirect if !{ hdr_beg(host) -i www. }
...
backend redirect
reqirep ^Host:\ (.*)$ Host:\ www.\1
redirect code 301 prefix /
That way the choice is taken when parsing the request and
the redirect is not conditionned to the rewrite.
Willy